diff --git a/agenda/data.py b/agenda/data.py index a90f697..5760f56 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -133,6 +133,39 @@ class AgendaData(typing.TypedDict, total=False): errors: list[tuple[str, Exception]] +def rocket_launch_events(rockets: list[thespacedevs.Summary]) -> list[Event]: + """Rocket launch events.""" + events: list[Event] = [] + for launch in rockets: + dt = None + + net_precision = launch["net_precision"] + skip = {"Year", "Month", "Quarter", "Fiscal Year"} + if net_precision == "Day": + dt = datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ").date() + elif ( + net_precision + and net_precision not in skip + and "Year" not in net_precision + and launch["t0_time"] + ): + dt = pytz.utc.localize( + datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ") + ) + + if not dt: + continue + + rocket_name = ( + f'{launch["rocket"]["full_name"]}: ' + + f'{launch["mission_name"] or "[no mission]"}' + ) + e = Event(name="rocket", date=dt, title=rocket_name) + events.append(e) + + return events + + async def get_data(now: datetime, config: flask.config.Config) -> AgendaData: """Get data to display on agenda dashboard.""" data_dir = config["DATA_DIR"] @@ -230,34 +263,7 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData: events += meetup.get_events(my_data) events += hn.whoishiring(last_year, next_year) events += carnival.rio_carnival_events(last_year, next_year) - - for launch in rockets: - dt = None - - net_precision = launch["net_precision"] - skip = {"Year", "Month", "Quarter", "Fiscal Year"} - if net_precision == "Day": - dt = datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ").date() - elif ( - net_precision - and net_precision not in skip - and "Year" not in net_precision - and launch["t0_time"] - ): - dt = pytz.utc.localize( - datetime.strptime(launch["net"], "%Y-%m-%dT%H:%M:%SZ") - ) - - if not dt: - continue - - rocket_name = ( - f'{launch["rocket"]["full_name"]}: ' - + f'{launch["mission_name"] or "[no mission]"}' - ) - e = Event(name="rocket", date=dt, title=rocket_name) - events.append(e) - + events += rocket_launch_events(rockets) events += [Event(name="today", date=today)] busy_events = [