From b4c923ac4e9bdf17ae272fb7426a3e9e57948805 Mon Sep 17 00:00:00 2001 From: Tilen Komel Date: Thu, 15 Oct 2026 17:16:50 +0200 Subject: [PATCH] Refactor timezone handling to use LOCAL_TIMEZONE consistently and log ingestion timestamps --- app/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 48e9aa3..4a5f76d 100644 --- a/app/main.py +++ b/app/main.py @@ -29,7 +29,7 @@ DISCORD_WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL", "") MAX_VISITS_PER_REQUEST = int(os.getenv("MAX_VISITS_PER_REQUEST", "100")) PAGE_SIZE_CHOICES = (25, 50, 100, 250) DEFAULT_PAGE_SIZE = 50 -VIEWER_TIMEZONE = ZoneInfo("Europe/Ljubljana") +LOCAL_TIMEZONE = ZoneInfo("Europe/Ljubljana") class Visit(BaseModel): url: HttpUrl @@ -132,6 +132,14 @@ def healthz(): async def receive_visits(batch: VisitBatch, authorization: Annotated[str | None, Header()] = None): require_token(authorization) stored = save_batch(batch) + ingestion_timestamp = datetime.now(timezone.utc).astimezone(LOCAL_TIMEZONE).isoformat(timespec="seconds") + logger.info( + "visit_batch_ingested ingestion_timestamp=%s timezone=Europe/Ljubljana device_id=%s accepted=%d stored=%d", + ingestion_timestamp, + batch.device_id, + len(batch.visits), + stored, + ) asyncio.create_task(post_discord(batch)) return {"accepted": len(batch.visits), "stored": stored} @@ -149,7 +157,7 @@ def viewer_timestamp(value: str) -> str: timestamp = datetime.fromisoformat(normalized) if timestamp.tzinfo is None: timestamp = timestamp.replace(tzinfo=timezone.utc) - return timestamp.astimezone(VIEWER_TIMEZONE).strftime("%m. %d. %H:%M") + return timestamp.astimezone(LOCAL_TIMEZONE).strftime("%m. %d. %H:%M") except (AttributeError, TypeError, ValueError): return str(value)