Compare commits

..

1 commit

Author SHA1 Message Date
ba82cf557e wip refactor 2025-08-30 11:58:17 -04:00

View file

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