Limit weather API calls to cron only, increase cache TTL to 24h

Web view was calling the OpenWeatherMap API directly on every request
(home + all trip locations), causing >1000 calls/day. Now web_view.py
uses cache_only=True everywhere so it never triggers live API calls —
update.py (cron) is the sole API caller. Also warms home location cache
in update_weather(), and increases TTL from 6h to 24h.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-03-14 09:27:56 +00:00
parent 04cb3e8179
commit feaefba03c
3 changed files with 45 additions and 6 deletions

View file

@ -410,7 +410,7 @@ def update_gandi(config: flask.config.Config) -> None:
def update_weather(config: flask.config.Config) -> None:
"""Refresh weather cache for all upcoming trips."""
"""Refresh weather cache for home and all upcoming trips."""
from datetime import date, timedelta
today = date.today()
@ -425,6 +425,20 @@ def update_weather(config: flask.config.Config) -> None:
seen: set[tuple[float, float]] = set()
count = 0
# Always include home location
home_lat = config.get("HOME_LATITUDE")
home_lon = config.get("HOME_LONGITUDE")
if home_lat is not None and home_lon is not None:
seen.add((home_lat, home_lon))
try:
agenda.weather.get_forecast(
config["DATA_DIR"], config["OPENWEATHERMAP_API_KEY"], home_lat, home_lon
)
count += 1
except Exception as exc:
print(f"weather update failed for home {home_lat},{home_lon}: {exc}")
for trip in upcoming:
latlon = agenda.weather.trip_latlon(trip)
if not latlon or latlon in seen: