Simplify code

This commit is contained in:
Edward Betts 2024-04-17 14:48:18 +01:00
parent 32e07d4ce4
commit 0fcaf76104
3 changed files with 11 additions and 17 deletions

View file

@ -1,5 +1,6 @@
"""Travel."""
import decimal
import json
import os
import typing
@ -43,7 +44,16 @@ def route_distances_as_json(route_distances: RouteDistances) -> str:
def parse_yaml(travel_type: str, data_dir: str) -> TravelList:
"""Parse flights YAML and return list of travel."""
filepath = os.path.join(data_dir, travel_type + ".yaml")
return typing.cast(TravelList, yaml.safe_load(open(filepath)))
items: TravelList = yaml.safe_load(open(filepath))
if not all(isinstance(item, dict) for item in items):
return items
for item in items:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
return items
def get_flights(data_dir: str) -> list[Event]:

View file

@ -101,11 +101,6 @@ def build_trip_list(
key=depart_datetime,
)
for item in travel_items:
price = item.get("price")
if price:
item["price"] = decimal.Decimal(price)
data = {
"travel": travel_items,
"accommodation": travel.parse_yaml("accommodation", data_dir),