Compare commits

..

1 commit

Author SHA1 Message Date
2030a4f7da WIP: refactor 2025-08-30 21:44:44 -04:00

50
main.py
View file

@ -20,19 +20,6 @@ POLLEN_MAX_INDEX = 12.0
POLLEN_PERCENTAGE_SCALE = 100 POLLEN_PERCENTAGE_SCALE = 100
HTTP_TIMEOUT = 10.0 HTTP_TIMEOUT = 10.0
# Location constants
DEFAULT_ZIP_CODE = "01970" # Salem, MA
DEFAULT_LATITUDE = "42.3554334"
DEFAULT_LONGITUDE = "-71.060511"
def get_required_env(key: str) -> str:
"""Get required environment variable or raise error."""
value = os.environ.get(key)
if not value:
raise ValueError(f"Required environment variable {key} is not set")
return value
class WeatherCondition(TypedDict): class WeatherCondition(TypedDict):
description: str description: str
@ -140,7 +127,7 @@ class FinalReport(TypedDict):
tomorrow: DailyData tomorrow: DailyData
app = FastAPI(title="trmnl weather & pollen report") app = FastAPI(title="TRMNL Weather & Pollen Report")
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)
@ -149,28 +136,23 @@ pollen_cache: TTLCache = TTLCache(maxsize=CACHE_MAX_SIZE, ttl=CACHE_TTL_SECONDS)
class Config: class Config:
"""Application configuration.""" """Application configuration."""
def __init__( def __init__(self):
self, self.zip_code = "01970" # Salem, MA
zip_code: str, self.latitude = "42.3554334"
latitude: str, self.longitude = "-71.060511"
longitude: str, self.weather_api_key = self._get_required_env("WEATHER_API_KEY")
weather_api_key: str, self.auth_token = self._get_required_env("AUTH_TOKEN")
auth_token: str,
): @staticmethod
self.zip_code = zip_code def _get_required_env(key: str) -> str:
self.latitude = latitude """Get required environment variable or raise error."""
self.longitude = longitude value = os.environ.get(key)
self.weather_api_key = weather_api_key if not value:
self.auth_token = auth_token raise ValueError(f"Required environment variable {key} is not set")
return value
config = Config( config = Config()
zip_code=DEFAULT_ZIP_CODE,
latitude=DEFAULT_LATITUDE,
longitude=DEFAULT_LONGITUDE,
weather_api_key=get_required_env("WEATHER_API_KEY"),
auth_token=get_required_env("AUTH_TOKEN"),
)
class DateTimeFormatter: class DateTimeFormatter: