Compare commits
1 commit
8b59d89820
...
91677f56ed
Author | SHA1 | Date | |
---|---|---|---|
91677f56ed |
1 changed files with 34 additions and 11 deletions
45
main.py
45
main.py
|
@ -189,7 +189,9 @@ 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:
|
||||
|
@ -271,7 +273,9 @@ class PollenData:
|
|||
PollenPeriod(
|
||||
{
|
||||
"index": pollen_percentage,
|
||||
"period": DateTimeFormatter.relative_day_to_date(period_type),
|
||||
"period": DateTimeFormatter.relative_day_to_date(
|
||||
period_type
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -298,7 +302,9 @@ 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)
|
||||
|
||||
|
@ -349,7 +355,8 @@ 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
|
||||
],
|
||||
}
|
||||
)
|
||||
|
@ -366,8 +373,12 @@ 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),
|
||||
}
|
||||
|
@ -505,11 +516,13 @@ 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()
|
||||
|
@ -525,12 +538,22 @@ 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"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue