diff --git a/agenda/travel.py b/agenda/travel.py index 27f7152..2c286f9 100644 --- a/agenda/travel.py +++ b/agenda/travel.py @@ -58,17 +58,21 @@ def parse_yaml(travel_type: str, data_dir: str) -> TravelList: def get_flights(data_dir: str) -> list[Event]: """Get travel events.""" - return [ - Event( - date=item["depart"], - end_date=item.get("arrive"), - name="transport", - title=f'✈️ {item["from"]} to {item["to"]} ({flight_number(item)})', - url=(item.get("url") if flask.g.user.is_authenticated else None), - ) - for item in parse_yaml("flights", data_dir) - if item["depart"].date() - ] + bookings = parse_yaml("flights", data_dir) + events = [] + for booking in bookings: + for item in booking["flights"]: + if not item["depart"].date(): + continue + e = Event( + date=item["depart"], + end_date=item.get("arrive"), + name="transport", + title=f'✈️ {item["from"]} to {item["to"]} ({flight_number(item)})', + url=(item.get("url") if flask.g.user.is_authenticated else None), + ) + events.append(e) + return events def get_trains(data_dir: str) -> list[Event]: diff --git a/agenda/trip.py b/agenda/trip.py index d7136f3..64754c0 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -67,18 +67,25 @@ def depart_datetime(item: StrDict) -> datetime: def load_flights(data_dir: str) -> list[StrDict]: """Load flights.""" - flights = load_travel("flight", data_dir) + bookings = load_travel("flight", data_dir) airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml"))) airports = travel.parse_yaml("airports", data_dir) - for flight in flights: - if flight["from"] in airports: - flight["from_airport"] = airports[flight["from"]] - if flight["to"] in airports: - flight["to_airport"] = airports[flight["to"]] - if "airline" in flight: - flight["airline_name"] = airlines.get(flight["airline"], "[unknown]") + flights = [] + for booking in bookings: + for flight in booking["flights"]: + if flight["from"] in airports: + flight["from_airport"] = airports[flight["from"]] + if flight["to"] in airports: + flight["to_airport"] = airports[flight["to"]] + if "airline" in flight: + flight["airline_name"] = airlines.get(flight["airline"], "[unknown]") - flight["distance"] = travel.flight_distance(flight) + flight["distance"] = travel.flight_distance(flight) + flight["type"] = booking["type"] + flight["trip"] = booking["trip"] + if "booking_reference" in booking: + flight["booking_reference"] = booking["booking_reference"] + flights.append(flight) return flights