From e42a17e61f5b838783496f430d01552b7dc257d7 Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:09:11 -0700 Subject: [PATCH] Auto-update: Tue Aug 6 22:09:11 PDT 2024 --- sijapi/routers/weather.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sijapi/routers/weather.py b/sijapi/routers/weather.py index 64adb32..6b8ec39 100644 --- a/sijapi/routers/weather.py +++ b/sijapi/routers/weather.py @@ -11,7 +11,7 @@ from fastapi.responses import JSONResponse from asyncpg.cursor import Cursor from httpx import AsyncClient from typing import Dict -from datetime import datetime as dt_datetime +from datetime import datetime as dt_datetime, date as dt_date from shapely.wkb import loads from binascii import unhexlify from sijapi import L, VISUALCROSSING_API_KEY, TZ, API, GEO @@ -26,6 +26,7 @@ def warn(text: str): logger.warning(text) def err(text: str): logger.error(text) def crit(text: str): logger.critical(text) + @weather.get("/weather/refresh", response_class=JSONResponse) async def get_refreshed_weather( date: str = Query(default=dt_datetime.now().strftime("%Y-%m-%d"), description="Enter a date in YYYY-MM-DD format, otherwise it will default to today."), @@ -53,7 +54,15 @@ async def get_refreshed_weather( raise HTTPException(status_code=404, detail="No weather data found for the given date and location") # Convert the day object to a JSON-serializable format - day_dict = {k: str(v) if isinstance(v, (dt_datetime, date)) else v for k, v in day.items()} + day_dict = {} + for k, v in day.items(): + if k == 'DailyWeather': + day_dict[k] = {kk: vv.isoformat() if isinstance(vv, (dt_datetime, dt_date)) else vv for kk, vv in v.items()} + elif k == 'HourlyWeather': + day_dict[k] = [{kk: vv.isoformat() if isinstance(vv, (dt_datetime, dt_date)) else vv for kk, vv in hour.items()} for hour in v] + else: + day_dict[k] = v.isoformat() if isinstance(v, (dt_datetime, dt_date)) else v + return JSONResponse(content={"weather": day_dict}, status_code=200) except HTTPException as e: