From f1a472a944f444a6bc5924a369d99a8784341d1c Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 18 May 2024 14:22:08 +0200 Subject: [PATCH] Better airport labels --- agenda/types.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/agenda/types.py b/agenda/types.py index 0f4c086..6770b46 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -43,6 +43,12 @@ class TripElement: detail: StrDict +def airport_label(airport: StrDict) -> str: + """Airport label: name and iata.""" + name = airport.get("alt_name") or airport["city"] + return f"{name} ({airport['iata']})" + + @dataclass class Trip: """Trip.""" @@ -204,12 +210,9 @@ class Trip: for item in self.travel: if item["type"] == "flight": - flight_from = item["from_airport"] - flight_to = item["to_airport"] name = ( - "✈️ " - + f"{flight_from['name']} ({flight_from['iata']}) -> " - + f"{flight_to['name']} ({flight_to['iata']})" + f"✈️ {airport_label(item['from_airport'])} → " + + f"{airport_label(item['to_airport'])}" ) elements.append(