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
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):
description: str
@ -140,7 +127,7 @@ class FinalReport(TypedDict):
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)
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:
"""Application configuration."""
def __init__(
self,
zip_code: str,
latitude: str,
longitude: str,
weather_api_key: str,
auth_token: str,
):
self.zip_code = zip_code
self.latitude = latitude
self.longitude = longitude
self.weather_api_key = weather_api_key
self.auth_token = auth_token
def __init__(self):
self.zip_code = "01970" # Salem, MA
self.latitude = "42.3554334"
self.longitude = "-71.060511"
self.weather_api_key = self._get_required_env("WEATHER_API_KEY")
self.auth_token = self._get_required_env("AUTH_TOKEN")
@staticmethod
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
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"),
)
config = Config()
class DateTimeFormatter: