Fix YAML validation outside Flask app context
This commit is contained in:
parent
574b4feb1f
commit
f38c5327ea
1 changed files with 14 additions and 7 deletions
|
|
@ -351,17 +351,18 @@ def build_trip_list(
|
|||
|
||||
|
||||
def add_coordinates_for_unbooked_flights(
|
||||
routes: list[StrDict], coordinates: list[StrDict]
|
||||
routes: list[StrDict], coordinates: list[StrDict], data_dir: str
|
||||
) -> None:
|
||||
"""Add coordinates for flights that haven't been booked yet."""
|
||||
if not (
|
||||
any(route["type"] == "unbooked_flight" for route in routes)
|
||||
and not any(pin["type"] == "airport" for pin in coordinates)
|
||||
):
|
||||
if not any(route["type"] == "unbooked_flight" for route in routes):
|
||||
return
|
||||
|
||||
data_dir = flask.current_app.config["PERSONAL_DATA"]
|
||||
airports = typing.cast(dict[str, StrDict], travel.parse_yaml("airports", data_dir))
|
||||
existing_airport_names = {
|
||||
typing.cast(str, pin["name"])
|
||||
for pin in coordinates
|
||||
if pin.get("type") == "airport" and isinstance(pin.get("name"), str)
|
||||
}
|
||||
iata_codes: set[str] = set()
|
||||
for route in routes:
|
||||
if route["type"] != "unbooked_flight":
|
||||
|
|
@ -375,14 +376,18 @@ def add_coordinates_for_unbooked_flights(
|
|||
airport = airports.get(iata)
|
||||
if not airport:
|
||||
continue
|
||||
airport_name = typing.cast(str, airport["name"])
|
||||
if airport_name in existing_airport_names:
|
||||
continue
|
||||
coordinates.append(
|
||||
{
|
||||
"name": airport["name"],
|
||||
"name": airport_name,
|
||||
"type": "airport",
|
||||
"latitude": airport["latitude"],
|
||||
"longitude": airport["longitude"],
|
||||
}
|
||||
)
|
||||
existing_airport_names.add(airport_name)
|
||||
|
||||
|
||||
def stations_from_travel(t: StrDict) -> list[StrDict]:
|
||||
|
|
@ -640,6 +645,8 @@ def get_coordinates_and_routes(
|
|||
routes.append(route)
|
||||
seen_routes.add(route["key"])
|
||||
|
||||
add_coordinates_for_unbooked_flights(routes, coordinates, data_dir)
|
||||
|
||||
for route in routes:
|
||||
if "geojson_filename" in route:
|
||||
route["geojson"] = read_geojson(data_dir, route.pop("geojson_filename"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue