fix(config,vibegram): triage wakes master by alias with wake urgency, event times in local tz

This commit is contained in:
hh
2026-08-30 20:34:17 +02:00
parent 05fcfb6447
commit ec55994fc7
2 changed files with 25 additions and 12 deletions
+19 -9
View File
@@ -20,6 +20,7 @@ from dataclasses import dataclass, field
from datetime import UTC, datetime
from pathlib import Path # noqa: TC003 - в аннотации dataclass
from typing import Any, Literal
from zoneinfo import ZoneInfo
import aiohttp
@@ -49,6 +50,8 @@ class Vibegram:
token: str
nick: str
repo: Path | None = None
tz: str = "UTC"
"""Время в строках событий - в этой зоне (хаб отдаёт UTC)."""
timeout: float = 15.0
max_chars: int = 8_000
_cursor: int = 0
@@ -126,7 +129,11 @@ class Vibegram:
async def pending(self, limit: int = 50) -> list[Event]:
"""Новые события с курсора хаба (для крона); запоминает их."""
data = await self._get(f"/api/pending?limit={limit}")
events = [e for e in map(_event, data.get("events", [])) if e is not None]
events = [
e
for e in (_event(raw, self.tz) for raw in data.get("events", []))
if e is not None
]
fresh = [e for e in events if e.id > self._cursor]
for e in fresh:
self._recent.append(e)
@@ -139,7 +146,7 @@ class Vibegram:
nick="system",
kind="plan",
text=f"план изменился (ревизия {ack}), ты его не подтвердил",
at=_now(),
at=_now(self.tz),
)
)
return fresh
@@ -210,18 +217,21 @@ class HubError(RuntimeError):
self.code = code
def _now() -> str:
return datetime.now(UTC).strftime("%m-%d %H:%M")
def _now(tz: str = "UTC") -> str:
return datetime.now(UTC).astimezone(ZoneInfo(tz)).strftime("%m-%d %H:%M")
def _when(iso: Any) -> str:
def _when(iso: Any, tz: str = "UTC") -> str:
try:
return datetime.fromisoformat(str(iso)).strftime("%m-%d %H:%M")
when = datetime.fromisoformat(str(iso))
except ValueError:
return _now()
return _now(tz)
if when.tzinfo is None:
when = when.replace(tzinfo=UTC)
return when.astimezone(ZoneInfo(tz)).strftime("%m-%d %H:%M")
def _event(raw: dict[str, Any]) -> Event | None:
def _event(raw: dict[str, Any], tz: str = "UTC") -> Event | None:
who = raw.get("nick") or "system"
kind = str(raw.get("kind") or "")
p = raw.get("payload") or {}
@@ -249,7 +259,7 @@ def _event(raw: dict[str, Any]) -> Event | None:
nick=str(who),
kind=kind,
text=text,
at=_when(raw.get("createdAt")),
at=_when(raw.get("createdAt"), tz),
)