Compare commits
3 commits
d5a92c9a8e
...
85ebaf7c84
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | 85ebaf7c84 | ||
Edward Betts | 5b2d248955 | ||
Edward Betts | f1a472a944 |
|
@ -43,6 +43,12 @@ class TripElement:
|
||||||
detail: StrDict
|
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
|
@dataclass
|
||||||
class Trip:
|
class Trip:
|
||||||
"""Trip."""
|
"""Trip."""
|
||||||
|
@ -204,12 +210,9 @@ class Trip:
|
||||||
|
|
||||||
for item in self.travel:
|
for item in self.travel:
|
||||||
if item["type"] == "flight":
|
if item["type"] == "flight":
|
||||||
flight_from = item["from_airport"]
|
|
||||||
flight_to = item["to_airport"]
|
|
||||||
name = (
|
name = (
|
||||||
"✈️ "
|
f"✈️ {airport_label(item['from_airport'])} → "
|
||||||
+ f"{flight_from['name']} ({flight_from['iata']}) -> "
|
+ f"{airport_label(item['to_airport'])}"
|
||||||
+ f"{flight_to['name']} ({flight_to['iata']})"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
elements.append(
|
elements.append(
|
||||||
|
@ -221,17 +224,18 @@ class Trip:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if item["type"] == "train":
|
if item["type"] == "train":
|
||||||
name = f"{item['from']} -> {item['to']}"
|
for leg in item["legs"]:
|
||||||
elements.append(
|
name = f"{leg['from']} → {leg['to']}"
|
||||||
TripElement(
|
elements.append(
|
||||||
when=item["depart"],
|
TripElement(
|
||||||
title=name,
|
when=leg["depart"],
|
||||||
detail=item,
|
title=name,
|
||||||
element_type="train",
|
detail=leg,
|
||||||
|
element_type="train",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
if item["type"] == "ferry":
|
if item["type"] == "ferry":
|
||||||
name = f"{item['from']} -> {item['to']}"
|
name = f"{item['from']} → {item['to']}"
|
||||||
elements.append(
|
elements.append(
|
||||||
TripElement(
|
TripElement(
|
||||||
when=item["depart"],
|
when=item["depart"],
|
||||||
|
|
Loading…
Reference in a new issue