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:
parent
10716f9874
commit
bca0cd2727
1 changed files with 5 additions and 6 deletions
11
update.py
11
update.py
|
|
@ -29,6 +29,9 @@ from agenda.types import StrDict
|
|||
from web_view import app
|
||||
|
||||
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
async def update_bank_holidays(config: flask.config.Config) -> None:
|
||||
"""Update cached copy of UK Bank holidays."""
|
||||
t0 = time()
|
||||
|
|
@ -318,8 +321,7 @@ def update_thespacedevs(config: flask.config.Config) -> None:
|
|||
"""
|
||||
rocket_dir = os.path.join(config["DATA_DIR"], "thespacedevs")
|
||||
|
||||
existing_data = agenda.thespacedevs.load_cached_launches(rocket_dir)
|
||||
assert existing_data
|
||||
existing_data = agenda.thespacedevs.load_cached_launches(rocket_dir) or {}
|
||||
|
||||
if agenda.thespacedevs.is_launches_cache_fresh(rocket_dir):
|
||||
return
|
||||
|
|
@ -411,16 +413,13 @@ def update_gandi(config: flask.config.Config) -> None:
|
|||
|
||||
def update_weather(config: flask.config.Config) -> None:
|
||||
"""Refresh weather cache for home and all upcoming trips."""
|
||||
from datetime import date, timedelta
|
||||
|
||||
today = date.today()
|
||||
forecast_window = today + timedelta(days=8)
|
||||
|
||||
trips = agenda.trip.build_trip_list()
|
||||
upcoming = [
|
||||
t
|
||||
for t in trips
|
||||
if (t.end or t.start) >= today and t.start <= forecast_window
|
||||
t for t in trips if (t.end or t.start) >= today and t.start <= forecast_window
|
||||
]
|
||||
|
||||
seen: set[tuple[float, float]] = set()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue