This commit is contained in:
doms9 2025-09-04 11:50:29 -04:00
parent 8ece1961e0
commit 00000d91c9
2 changed files with 21 additions and 13 deletions

View file

@ -3,7 +3,7 @@
import asyncio
import json
import re
from datetime import datetime
from datetime import datetime, timedelta
from pathlib import Path
from urllib.parse import urljoin
@ -36,13 +36,17 @@ async def refresh_api_cache(client: httpx.AsyncClient, url: str) -> dict:
return r.json()
def load_cache() -> dict[str, dict[str, str | str]]:
def load_cache() -> dict[str, dict[str, str | float]]:
try:
data: dict = json.loads(CACHE_FILE.read_text(encoding="utf-8"))
data: dict[str, dict[str, str | float]] = json.loads(
CACHE_FILE.read_text(encoding="utf-8")
)
age: float = now.timestamp() - data.get("timestamp", 0)
return {k: v for k, v in data.items() if age < 14400} # 4 hours
return {
k: v
for k, v in data.items()
if now.timestamp() - data[k].get("timestamp", 0) < 14400 # 4 hours
}
except (FileNotFoundError, json.JSONDecodeError):
return {}
@ -156,9 +160,9 @@ async def get_events(
if key in cached_keys:
continue
start_dt = datetime.fromtimestamp(start_ts, tz=TZ)
start_dt = datetime.fromtimestamp(start_ts, tz=TZ) - timedelta(minutes=30)
end_dt = datetime.fromtimestamp(end_ts, tz=TZ)
end_dt = datetime.fromtimestamp(end_ts, tz=TZ) + timedelta(minutes=30)
if not start_dt <= now < end_dt:
continue