Compare commits
1 commit
2030a4f7da
...
bb25e7bbee
Author | SHA1 | Date | |
---|---|---|---|
bb25e7bbee |
1 changed files with 34 additions and 16 deletions
50
main.py
50
main.py
|
@ -20,6 +20,19 @@ 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
|
||||
|
@ -127,7 +140,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)
|
||||
|
@ -136,23 +149,28 @@ pollen_cache: TTLCache = TTLCache(maxsize=CACHE_MAX_SIZE, ttl=CACHE_TTL_SECONDS)
|
|||
class Config:
|
||||
"""Application configuration."""
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue