Compare commits

..

1 commit

Author SHA1 Message Date
8b59d89820 WIP: refactor 2025-09-01 09:55:00 -04:00

45
main.py
View file

@ -189,9 +189,7 @@ class DateTimeFormatter:
@staticmethod
def format_datetime(dt: datetime) -> str:
"""Format datetime as date and time string."""
return (
f"{DateTimeFormatter.format_date(dt)} {DateTimeFormatter.format_time(dt)}"
)
return f"{DateTimeFormatter.format_date(dt)} {DateTimeFormatter.format_time(dt)}"
@staticmethod
def relative_day_to_date(relative_day: str) -> str:
@ -273,9 +271,7 @@ class PollenData:
PollenPeriod(
{
"index": pollen_percentage,
"period": DateTimeFormatter.relative_day_to_date(
period_type
),
"period": DateTimeFormatter.relative_day_to_date(period_type),
}
)
)
@ -302,9 +298,7 @@ class WeatherService:
@staticmethod
@error_handler
async def fetch_weather(
latitude: str, longitude: str, api_key: str
) -> list[WeatherReport]:
async def fetch_weather(latitude: str, longitude: str, api_key: str) -> list[WeatherReport]:
"""Fetch weather data from OpenWeatherMap API."""
cache_key = (latitude, longitude)
@ -355,8 +349,7 @@ class WeatherService:
"current_pressure": current["pressure"],
"current_desc": current["weather"][0]["description"],
"periods": [
WeatherService._format_daily_period(period)
for period in daily_periods
WeatherService._format_daily_period(period) for period in daily_periods
],
}
)
@ -373,12 +366,8 @@ class WeatherService:
"high": int(round(period["temp"]["max"])),
"desc": period["weather"][0]["description"],
"humidity": period["humidity"],
"sunrise": DateTimeFormatter.format_time(
datetime.fromtimestamp(period["sunrise"])
),
"sunset": DateTimeFormatter.format_time(
datetime.fromtimestamp(period["sunset"])
),
"sunrise": DateTimeFormatter.format_time(datetime.fromtimestamp(period["sunrise"])),
"sunset": DateTimeFormatter.format_time(datetime.fromtimestamp(period["sunset"])),
"pressure": period["pressure"],
"period": DateTimeFormatter.format_date(period_dt),
}
@ -516,13 +505,11 @@ async def get_weather_pollen_report(token: str) -> FinalReport:
pollen_data, weather_data = await asyncio.gather(
PollenService.fetch_pollen(config.zip_code),
WeatherService.fetch_weather(
config.latitude, config.longitude, config.weather_api_key
),
WeatherService.fetch_weather(config.latitude, config.longitude, config.weather_api_key),
)
pollen_periods, weather_periods, current_weather_info = (
DataAggregator.create_periods_lookup(pollen_data, weather_data)
pollen_periods, weather_periods, current_weather_info = DataAggregator.create_periods_lookup(
pollen_data, weather_data
)
now = datetime.now()
@ -538,22 +525,12 @@ async def get_weather_pollen_report(token: str) -> FinalReport:
}
)
today_data = DataAggregator.build_daily_data(
today_date, pollen_periods, weather_periods
)
today_data = DataAggregator.build_daily_data(today_date, pollen_periods, weather_periods)
if today_data:
result["today"] = today_data
tomorrow_data = DataAggregator.build_daily_data(
tomorrow_date, pollen_periods, weather_periods
)
tomorrow_data = DataAggregator.build_daily_data(tomorrow_date, pollen_periods, weather_periods)
if tomorrow_data:
result["tomorrow"] = tomorrow_data
return result
@app.get("/health")
async def health_check() -> dict[str, str]:
"""Health check endpoint."""
return {"status": "healthy"}