change calculation to strictly days
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,3 +2,7 @@ utils/__pycache__/__init__.cpython-313.pyc
|
|||||||
utils/__pycache__/geocode.cpython-313.pyc
|
utils/__pycache__/geocode.cpython-313.pyc
|
||||||
utils/__pycache__/weather.cpython-313.pyc
|
utils/__pycache__/weather.cpython-313.pyc
|
||||||
__pycache__/config.cpython-313.pyc
|
__pycache__/config.cpython-313.pyc
|
||||||
|
__pycache__/config.cpython-312.pyc
|
||||||
|
utils/__pycache__/geocode.cpython-312.pyc
|
||||||
|
utils/__pycache__/weather.cpython-312.pyc
|
||||||
|
utils/__pycache__/__init__.cpython-312.pyc
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ async def get_today_snowfall_async(lat, lon):
|
|||||||
tz_name = tf.timezone_at(lat=lat, lng=lon) or "UTC"
|
tz_name = tf.timezone_at(lat=lat, lng=lon) or "UTC"
|
||||||
|
|
||||||
async with httpx.AsyncClient(timeout=5) as client:
|
async with httpx.AsyncClient(timeout=5) as client:
|
||||||
params = {"latitude": lat, "longitude": lon, "hourly": "snowfall", "timezone": tz_name}
|
params = {"latitude": lat, "longitude": lon, "daily": "snowfall_sum", "timezone": tz_name}
|
||||||
r = await client.get(OPEN_METEO_URL, params=params)
|
r = await client.get(OPEN_METEO_URL, params=params)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
hourly = data.get("hourly", {})
|
daily = data.get("daily", {})
|
||||||
times = hourly.get("time", [])
|
days = daily.get("time", [])
|
||||||
snow_values = hourly.get("snowfall", [])
|
snow_values = daily.get("snowfall_sum", [])
|
||||||
|
|
||||||
today_str = datetime.now(pytz.timezone(tz_name)).date().isoformat()
|
today_str = datetime.now(pytz.timezone(tz_name)).date().isoformat()
|
||||||
|
|
||||||
snowfall_cm = 0.0
|
snowfall_cm = 0.0
|
||||||
snowing_now = False
|
snowing_now = False
|
||||||
for t, s in zip(times, snow_values):
|
for d, s in zip(days, snow_values):
|
||||||
if t.startswith(today_str):
|
if d.startswith(today_str):
|
||||||
snowfall_cm += s
|
snowfall_cm += s
|
||||||
if s > 0:
|
if s > 0:
|
||||||
snowing_now = True
|
snowing_now = True
|
||||||
|
|||||||
Reference in New Issue
Block a user