parent
5ab9d93484
commit
19732a3ef1
|
@ -58,17 +58,21 @@ def parse_yaml(travel_type: str, data_dir: str) -> TravelList:
|
||||||
|
|
||||||
def get_flights(data_dir: str) -> list[Event]:
|
def get_flights(data_dir: str) -> list[Event]:
|
||||||
"""Get travel events."""
|
"""Get travel events."""
|
||||||
return [
|
bookings = parse_yaml("flights", data_dir)
|
||||||
Event(
|
events = []
|
||||||
|
for booking in bookings:
|
||||||
|
for item in booking["flights"]:
|
||||||
|
if not item["depart"].date():
|
||||||
|
continue
|
||||||
|
e = Event(
|
||||||
date=item["depart"],
|
date=item["depart"],
|
||||||
end_date=item.get("arrive"),
|
end_date=item.get("arrive"),
|
||||||
name="transport",
|
name="transport",
|
||||||
title=f'✈️ {item["from"]} to {item["to"]} ({flight_number(item)})',
|
title=f'✈️ {item["from"]} to {item["to"]} ({flight_number(item)})',
|
||||||
url=(item.get("url") if flask.g.user.is_authenticated else None),
|
url=(item.get("url") if flask.g.user.is_authenticated else None),
|
||||||
)
|
)
|
||||||
for item in parse_yaml("flights", data_dir)
|
events.append(e)
|
||||||
if item["depart"].date()
|
return events
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_trains(data_dir: str) -> list[Event]:
|
def get_trains(data_dir: str) -> list[Event]:
|
||||||
|
|
|
@ -67,10 +67,12 @@ def depart_datetime(item: StrDict) -> datetime:
|
||||||
|
|
||||||
def load_flights(data_dir: str) -> list[StrDict]:
|
def load_flights(data_dir: str) -> list[StrDict]:
|
||||||
"""Load flights."""
|
"""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")))
|
airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml")))
|
||||||
airports = travel.parse_yaml("airports", data_dir)
|
airports = travel.parse_yaml("airports", data_dir)
|
||||||
for flight in flights:
|
flights = []
|
||||||
|
for booking in bookings:
|
||||||
|
for flight in booking["flights"]:
|
||||||
if flight["from"] in airports:
|
if flight["from"] in airports:
|
||||||
flight["from_airport"] = airports[flight["from"]]
|
flight["from_airport"] = airports[flight["from"]]
|
||||||
if flight["to"] in airports:
|
if flight["to"] in airports:
|
||||||
|
@ -79,6 +81,11 @@ def load_flights(data_dir: str) -> list[StrDict]:
|
||||||
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
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
|
return flights
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue