Use pattern matching: train/flight/ferry
This commit is contained in:
parent
7d803e0267
commit
868c1407b5
|
@ -235,17 +235,17 @@ def get_locations(trip: Trip) -> dict[str, StrDict]:
|
|||
|
||||
station_list = []
|
||||
for t in trip.travel:
|
||||
if t["type"] == "train":
|
||||
match t["type"]:
|
||||
case "train":
|
||||
station_list += [t["from_station"], t["to_station"]]
|
||||
for leg in t["legs"]:
|
||||
station_list.append(leg["from_station"])
|
||||
station_list.append(leg["to_station"])
|
||||
elif t["type"] == "flight":
|
||||
case "flight":
|
||||
for field in "from_airport", "to_airport":
|
||||
if field in t:
|
||||
locations["airport"][t[field]["iata"]] = t[field]
|
||||
else:
|
||||
assert t["type"] == "ferry"
|
||||
case "ferry":
|
||||
for field in "from_terminal", "to_terminal":
|
||||
terminal = t[field]
|
||||
locations["ferry_terminal"][terminal["name"]] = terminal
|
||||
|
|
Loading…
Reference in a new issue