Adjust travel page to show flights grouped by booking with booking reference and price
Closes: #152
This commit is contained in:
parent
19732a3ef1
commit
6d6e416df3
4 changed files with 65 additions and 15 deletions
|
|
@ -65,12 +65,11 @@ def depart_datetime(item: StrDict) -> datetime:
|
|||
return datetime.combine(depart, time.min).replace(tzinfo=ZoneInfo("UTC"))
|
||||
|
||||
|
||||
def load_flights(data_dir: str) -> list[StrDict]:
|
||||
"""Load flights."""
|
||||
def load_flight_bookings(data_dir: str) -> list[StrDict]:
|
||||
"""Load flight bookings."""
|
||||
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)
|
||||
flights = []
|
||||
for booking in bookings:
|
||||
for flight in booking["flights"]:
|
||||
if flight["from"] in airports:
|
||||
|
|
@ -81,10 +80,17 @@ def load_flights(data_dir: str) -> list[StrDict]:
|
|||
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
||||
|
||||
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"]
|
||||
return bookings
|
||||
|
||||
|
||||
def load_flights(data_dir: str) -> list[StrDict]:
|
||||
"""Load flights."""
|
||||
flights = []
|
||||
for booking in load_flight_bookings(data_dir):
|
||||
for flight in booking["flights"]:
|
||||
for f in "type", "trip", "booking_reference":
|
||||
if f in booking:
|
||||
flight[f] = booking[f]
|
||||
flights.append(flight)
|
||||
return flights
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue