diff --git a/main.py b/main.py index ca79217..2ebfe33 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ import httpx logger = logging.getLogger("uvicorn.error") +# Constants EASTERN_TZ = zoneinfo.ZoneInfo("America/New_York") CACHE_TTL_SECONDS = 900 # 15 minutes CACHE_MAX_SIZE = 100 @@ -112,8 +113,10 @@ class FinalReport(TypedDict): today: DailyData tomorrow: DailyData +# Initialize FastAPI app app = FastAPI(title="TRMNL Weather & Pollen Report") +# Cache instances weather_cache: TTLCache = TTLCache(maxsize=CACHE_MAX_SIZE, ttl=CACHE_TTL_SECONDS) pollen_cache: TTLCache = TTLCache(maxsize=CACHE_MAX_SIZE, ttl=CACHE_TTL_SECONDS) @@ -409,6 +412,7 @@ class DataAggregator: p["period"]: p for p in weather_data[0]["periods"] } + # Add current weather data as a separate structure current_weather_info = CurrentWeatherData({ "temp": 0, "feels_like": 0, @@ -460,6 +464,7 @@ async def get_weather_pollen_report(token: str) -> FinalReport: today_date = DateTimeFormatter.format_date(now) tomorrow_date = DateTimeFormatter.format_date(now + timedelta(days=1)) + # Build response result: FinalReport = FinalReport({ "fetched_at": DateTimeFormatter.format_datetime(now), "current": current_weather_info,