Compare commits
2 commits
1e39e75117
...
e66945a825
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | e66945a825 | ||
Edward Betts | e814e1b135 |
|
@ -93,6 +93,7 @@ def load_flight_bookings(data_dir: str) -> list[StrDict]:
|
||||||
"""Load flight bookings."""
|
"""Load flight bookings."""
|
||||||
bookings = load_travel("flight", "flights", data_dir)
|
bookings = load_travel("flight", "flights", data_dir)
|
||||||
airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml")))
|
airlines = yaml.safe_load(open(os.path.join(data_dir, "airlines.yaml")))
|
||||||
|
iata = {a["iata"]: a["name"] for a in airlines}
|
||||||
airports = travel.parse_yaml("airports", data_dir)
|
airports = travel.parse_yaml("airports", data_dir)
|
||||||
for booking in bookings:
|
for booking in bookings:
|
||||||
for flight in booking["flights"]:
|
for flight in booking["flights"]:
|
||||||
|
@ -101,7 +102,7 @@ def load_flight_bookings(data_dir: str) -> list[StrDict]:
|
||||||
if flight["to"] in airports:
|
if flight["to"] in airports:
|
||||||
flight["to_airport"] = airports[flight["to"]]
|
flight["to_airport"] = airports[flight["to"]]
|
||||||
if "airline" in flight:
|
if "airline" in flight:
|
||||||
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
flight["airline_name"] = iata.get(flight["airline"], "[unknown]")
|
||||||
|
|
||||||
flight["distance"] = travel.flight_distance(flight)
|
flight["distance"] = travel.flight_distance(flight)
|
||||||
return bookings
|
return bookings
|
||||||
|
|
111
validate_yaml.py
111
validate_yaml.py
|
@ -13,43 +13,86 @@ import agenda.trip
|
||||||
import agenda.types
|
import agenda.types
|
||||||
|
|
||||||
config = __import__("config.default", fromlist=[""])
|
config = __import__("config.default", fromlist=[""])
|
||||||
|
|
||||||
data_dir = config.PERSONAL_DATA
|
data_dir = config.PERSONAL_DATA
|
||||||
|
|
||||||
trip_list = agenda.trip.build_trip_list(data_dir)
|
|
||||||
print(len(trip_list), "trips")
|
|
||||||
|
|
||||||
coords, routes = agenda.trip.get_coordinates_and_routes(trip_list, data_dir)
|
def check_trips() -> None:
|
||||||
print(len(coords), "coords")
|
"""Check trips."""
|
||||||
print(len(routes), "routes")
|
trip_list = agenda.trip.build_trip_list(data_dir)
|
||||||
|
print(len(trip_list), "trips")
|
||||||
|
|
||||||
flights = agenda.travel.parse_yaml("flights", data_dir)
|
coords, routes = agenda.trip.get_coordinates_and_routes(trip_list, data_dir)
|
||||||
print(len(flights), "flights")
|
print(len(coords), "coords")
|
||||||
|
print(len(routes), "routes")
|
||||||
trains = agenda.travel.parse_yaml("trains", data_dir)
|
|
||||||
print(len(trains), "trains")
|
|
||||||
|
|
||||||
conferences = agenda.conference.get_list(os.path.join(data_dir, "conferences.yaml"))
|
|
||||||
print(len(conferences), "conferences")
|
|
||||||
|
|
||||||
today = date.today()
|
|
||||||
last_year = today - timedelta(days=365)
|
|
||||||
next_year = today + timedelta(days=2 * 365)
|
|
||||||
|
|
||||||
events = agenda.events_yaml.read(data_dir, last_year, next_year)
|
|
||||||
print(len(events), "events")
|
|
||||||
|
|
||||||
airports = typing.cast(
|
|
||||||
dict[str, agenda.types.StrDict], agenda.travel.parse_yaml("airports", data_dir)
|
|
||||||
)
|
|
||||||
print(len(airports), "airports")
|
|
||||||
for airport in airports.values():
|
|
||||||
assert "country" in airport
|
|
||||||
assert agenda.get_country(airport["country"])
|
|
||||||
|
|
||||||
|
|
||||||
stations = agenda.travel.parse_yaml("stations", data_dir)
|
def check_flights() -> None:
|
||||||
print(len(stations), "stations")
|
"""Check flights."""
|
||||||
for station in stations:
|
flights = agenda.travel.parse_yaml("flights", data_dir)
|
||||||
assert "country" in station
|
print(len(flights), "flights")
|
||||||
assert agenda.get_country(station["country"])
|
|
||||||
|
|
||||||
|
def check_trains() -> None:
|
||||||
|
"""Check trains."""
|
||||||
|
trains = agenda.travel.parse_yaml("trains", data_dir)
|
||||||
|
print(len(trains), "trains")
|
||||||
|
|
||||||
|
|
||||||
|
def check_conferences() -> None:
|
||||||
|
"""Check conferences."""
|
||||||
|
conferences = agenda.conference.get_list(os.path.join(data_dir, "conferences.yaml"))
|
||||||
|
print(len(conferences), "conferences")
|
||||||
|
|
||||||
|
|
||||||
|
def check_events() -> None:
|
||||||
|
"""Check events."""
|
||||||
|
today = date.today()
|
||||||
|
last_year = today - timedelta(days=365)
|
||||||
|
next_year = today + timedelta(days=2 * 365)
|
||||||
|
|
||||||
|
events = agenda.events_yaml.read(data_dir, last_year, next_year)
|
||||||
|
print(len(events), "events")
|
||||||
|
|
||||||
|
|
||||||
|
def check_airports() -> None:
|
||||||
|
"""Check airports."""
|
||||||
|
airports = typing.cast(
|
||||||
|
dict[str, agenda.types.StrDict], agenda.travel.parse_yaml("airports", data_dir)
|
||||||
|
)
|
||||||
|
print(len(airports), "airports")
|
||||||
|
for airport in airports.values():
|
||||||
|
assert "country" in airport
|
||||||
|
assert agenda.get_country(airport["country"])
|
||||||
|
|
||||||
|
|
||||||
|
def check_stations() -> None:
|
||||||
|
"""Check stations."""
|
||||||
|
stations = agenda.travel.parse_yaml("stations", data_dir)
|
||||||
|
print(len(stations), "stations")
|
||||||
|
for station in stations:
|
||||||
|
assert "country" in station
|
||||||
|
assert agenda.get_country(station["country"])
|
||||||
|
|
||||||
|
|
||||||
|
def check_airlines() -> None:
|
||||||
|
"""Check airlines."""
|
||||||
|
airlines = agenda.travel.parse_yaml("airlines", data_dir)
|
||||||
|
print(len(airlines), "airlines")
|
||||||
|
for airline in airlines:
|
||||||
|
assert airline.keys() == {"icao", "iata", "name"}
|
||||||
|
|
||||||
|
|
||||||
|
def check() -> None:
|
||||||
|
"""Validate personal data YAML files."""
|
||||||
|
check_trips()
|
||||||
|
check_flights()
|
||||||
|
check_trains()
|
||||||
|
check_conferences()
|
||||||
|
check_events()
|
||||||
|
check_airports()
|
||||||
|
check_stations()
|
||||||
|
check_airlines()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
check()
|
||||||
|
|
Loading…
Reference in a new issue