Minor cleanup in update.py

- Move datetime import to module level
- Replace assert on load_cached_launches with or {} fallback so the
  updater doesn't crash when the cache file is absent
- Condense upcoming-trips list comprehension to one line

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-03-14 11:05:32 +00:00
parent 10716f9874
commit bca0cd2727

View file

@ -29,6 +29,9 @@ from agenda.types import StrDict
from web_view import app from web_view import app
from datetime import date, timedelta
async def update_bank_holidays(config: flask.config.Config) -> None: async def update_bank_holidays(config: flask.config.Config) -> None:
"""Update cached copy of UK Bank holidays.""" """Update cached copy of UK Bank holidays."""
t0 = time() t0 = time()
@ -318,8 +321,7 @@ def update_thespacedevs(config: flask.config.Config) -> None:
""" """
rocket_dir = os.path.join(config["DATA_DIR"], "thespacedevs") rocket_dir = os.path.join(config["DATA_DIR"], "thespacedevs")
existing_data = agenda.thespacedevs.load_cached_launches(rocket_dir) existing_data = agenda.thespacedevs.load_cached_launches(rocket_dir) or {}
assert existing_data
if agenda.thespacedevs.is_launches_cache_fresh(rocket_dir): if agenda.thespacedevs.is_launches_cache_fresh(rocket_dir):
return return
@ -411,16 +413,13 @@ def update_gandi(config: flask.config.Config) -> None:
def update_weather(config: flask.config.Config) -> None: def update_weather(config: flask.config.Config) -> None:
"""Refresh weather cache for home and all upcoming trips.""" """Refresh weather cache for home and all upcoming trips."""
from datetime import date, timedelta
today = date.today() today = date.today()
forecast_window = today + timedelta(days=8) forecast_window = today + timedelta(days=8)
trips = agenda.trip.build_trip_list() trips = agenda.trip.build_trip_list()
upcoming = [ upcoming = [
t t for t in trips if (t.end or t.start) >= today and t.start <= forecast_window
for t in trips
if (t.end or t.start) >= today and t.start <= forecast_window
] ]
seen: set[tuple[float, float]] = set() seen: set[tuple[float, float]] = set()