trip: use flight_destinations rules for unbooked routes
This commit is contained in:
parent
11ab5f6d28
commit
5e2fb72fef
1 changed files with 13 additions and 7 deletions
|
|
@ -24,16 +24,17 @@ class Airline(typing.TypedDict, total=False):
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
|
||||||
def load_unbooked_flight_origin_rules(
|
def load_flight_destination_rules(
|
||||||
data_dir: str,
|
data_dir: str,
|
||||||
) -> list[tuple[str, set[str]]]:
|
) -> list[tuple[str, set[str]]]:
|
||||||
"""Load unbooked flight origin rules from personal data.
|
"""Load flight destination rules from personal data.
|
||||||
|
|
||||||
YAML schema:
|
YAML schema:
|
||||||
- from: BRS
|
- origin: BRS
|
||||||
|
airline: U2
|
||||||
destinations: [AGP, ALC]
|
destinations: [AGP, ALC]
|
||||||
"""
|
"""
|
||||||
filename = os.path.join(data_dir, "unbooked_flight_origins.yaml")
|
filename = os.path.join(data_dir, "flight_destinations.yaml")
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
@ -45,9 +46,14 @@ def load_unbooked_flight_origin_rules(
|
||||||
for item in raw:
|
for item in raw:
|
||||||
if not isinstance(item, dict):
|
if not isinstance(item, dict):
|
||||||
continue
|
continue
|
||||||
from_iata = item.get("from")
|
from_iata = item.get("origin")
|
||||||
|
airline = item.get("airline")
|
||||||
destinations = item.get("destinations")
|
destinations = item.get("destinations")
|
||||||
if not isinstance(from_iata, str) or not isinstance(destinations, list):
|
if (
|
||||||
|
not isinstance(from_iata, str)
|
||||||
|
or not isinstance(airline, str)
|
||||||
|
or not isinstance(destinations, list)
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
destination_set = {d.upper() for d in destinations if isinstance(d, str)}
|
destination_set = {d.upper() for d in destinations if isinstance(d, str)}
|
||||||
if destination_set:
|
if destination_set:
|
||||||
|
|
@ -580,7 +586,7 @@ def get_trip_routes(trip: Trip, data_dir: str) -> list[StrDict]:
|
||||||
return routes
|
return routes
|
||||||
|
|
||||||
airports = typing.cast(dict[str, StrDict], travel.parse_yaml("airports", data_dir))
|
airports = typing.cast(dict[str, StrDict], travel.parse_yaml("airports", data_dir))
|
||||||
origin_rules = load_unbooked_flight_origin_rules(data_dir)
|
origin_rules = load_flight_destination_rules(data_dir)
|
||||||
|
|
||||||
unbooked_routes = []
|
unbooked_routes = []
|
||||||
for item in trip.conferences:
|
for item in trip.conferences:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue