No need for the UnknownStation exception

This commit is contained in:
Edward Betts 2024-10-02 15:39:19 +01:00
parent 868c1407b5
commit 237db73b5d

View file

@ -13,12 +13,6 @@ from agenda import travel
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]:
"""Read flight and train journeys."""
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
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:
"""Lookup stations and add to train or leg."""
item["from_station"] = get_station(item["from"], by_name)
item["to_station"] = get_station(item["to"], by_name)
item["from_station"] = by_name[item["from"]]
item["to_station"] = by_name[item["to"]]
def load_trains(