From 237db73b5db734c2cbc28d857d304bb7aedc20b6 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 2 Oct 2024 15:39:19 +0100 Subject: [PATCH] No need for the UnknownStation exception --- agenda/trip.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index a3cc35c..fe49bdf 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -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(