Handle missing space launch

This commit is contained in:
Edward Betts 2024-06-26 08:48:58 +01:00
parent f4557d14e8
commit b8ed1d5d65

View file

@ -99,10 +99,15 @@ Agenda: https://edwardbetts.com/agenda/
def report_space_launch_change(
config: flask.config.Config, prev_launch: StrDict, cur_launch: StrDict
config: flask.config.Config, prev_launch: StrDict | None, cur_launch: StrDict | None
) -> None:
"""Send mail to announce change to space launch data."""
subject = f'Change to {cur_launch["name"]}'
if cur_launch:
name = cur_launch["name"]
else:
assert prev_launch
name = prev_launch["name"]
subject = f"Change to {name}"
body = f"""
A space launch of interest was updated.
@ -119,9 +124,11 @@ New launch data
send_mail(config, subject, body)
def get_launch_by_slug(data: StrDict, slug: str) -> StrDict:
def get_launch_by_slug(data: StrDict, slug: str) -> StrDict | None:
"""Find last update for space launch."""
return {item["slug"]: typing.cast(StrDict, item) for item in data["results"]}[slug]
return {item["slug"]: typing.cast(StrDict, item) for item in data["results"]}.get(
slug
)
def update_thespacedevs(config: flask.config.Config) -> None:
@ -142,8 +149,11 @@ def update_thespacedevs(config: flask.config.Config) -> None:
for slug in config["FOLLOW_LAUNCHES"]:
prev, cur = prev_launches[slug], cur_launches[slug]
if prev["last_updated"] != cur["last_updated"]:
report_space_launch_change(config, prev, cur)
if prev is None and cur is None:
continue
if prev and cur and prev["last_updated"] == cur["last_updated"]:
continue
report_space_launch_change(config, prev, cur)
time_taken = time() - t0
if not sys.stdin.isatty():