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