No need for the UnknownStation exception
This commit is contained in:
parent
868c1407b5
commit
237db73b5d
|
@ -13,12 +13,6 @@ from agenda import travel
|
||||||
from agenda.types import StrDict, Trip
|
from agenda.types import StrDict, Trip
|
||||||
|
|
||||||
|
|
||||||
class UnknownStation(Exception):
|
|
||||||
"""Unknown station."""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def load_travel(travel_type: str, plural: str, data_dir: str) -> list[StrDict]:
|
def load_travel(travel_type: str, plural: str, data_dir: str) -> list[StrDict]:
|
||||||
"""Read flight and train journeys."""
|
"""Read flight and train journeys."""
|
||||||
items = travel.parse_yaml(plural, data_dir)
|
items = travel.parse_yaml(plural, data_dir)
|
||||||
|
@ -27,18 +21,10 @@ def load_travel(travel_type: str, plural: str, data_dir: str) -> list[StrDict]:
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
def get_station(name: str, by_name: dict[str, StrDict]) -> StrDict:
|
|
||||||
"""Get station by name."""
|
|
||||||
try:
|
|
||||||
return by_name[name]
|
|
||||||
except IndexError:
|
|
||||||
raise UnknownStation(name)
|
|
||||||
|
|
||||||
|
|
||||||
def add_station_objects(item: StrDict, by_name: dict[str, StrDict]) -> None:
|
def add_station_objects(item: StrDict, by_name: dict[str, StrDict]) -> None:
|
||||||
"""Lookup stations and add to train or leg."""
|
"""Lookup stations and add to train or leg."""
|
||||||
item["from_station"] = get_station(item["from"], by_name)
|
item["from_station"] = by_name[item["from"]]
|
||||||
item["to_station"] = get_station(item["to"], by_name)
|
item["to_station"] = by_name[item["to"]]
|
||||||
|
|
||||||
|
|
||||||
def load_trains(
|
def load_trains(
|
||||||
|
|
Loading…
Reference in a new issue