feat(briefing): weather × calendar cross-reference — rain warnings for outdoor events
This commit is contained in:
@@ -232,6 +232,32 @@ async def fetch_current_conditions(lat: float, lon: float) -> dict | None:
|
||||
return None
|
||||
|
||||
|
||||
async def fetch_hourly_precip(lat: float, lon: float) -> dict[str, int]:
|
||||
"""Fetch today's hourly precipitation probabilities.
|
||||
|
||||
Returns a dict of ISO hour string → probability percentage, e.g.:
|
||||
{"2026-04-08T14:00": 65, "2026-04-08T15:00": 80, ...}
|
||||
"""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
resp = await client.get(OPEN_METEO_URL, params={
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"hourly": "precipitation_probability",
|
||||
"forecast_days": 1,
|
||||
"timezone": "auto",
|
||||
})
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
hourly = data.get("hourly", {})
|
||||
times = hourly.get("time", [])
|
||||
probs = hourly.get("precipitation_probability", [])
|
||||
return {t: p for t, p in zip(times, probs) if p is not None}
|
||||
except Exception:
|
||||
logger.debug("Failed to fetch hourly precip for %s, %s", lat, lon, exc_info=True)
|
||||
return {}
|
||||
|
||||
|
||||
async def _fetch_open_meteo(lat: float, lon: float) -> dict:
|
||||
"""Fetch 7-day forecast from Open-Meteo with current conditions and yesterday's data."""
|
||||
async with httpx.AsyncClient(timeout=15.0) as client:
|
||||
|
||||
Reference in New Issue
Block a user