Document personal data YAML formats
This commit is contained in:
parent
fc82cf280a
commit
7ec36a5e80
2 changed files with 776 additions and 6 deletions
|
|
@ -36,6 +36,23 @@ def check_currency(item: agenda.types.StrDict) -> None:
|
|||
sys.exit(-1)
|
||||
|
||||
|
||||
def check_country_code(
|
||||
item: agenda.types.StrDict, source: str, required: bool = True
|
||||
) -> None:
|
||||
"""Throw error if country code is missing or invalid."""
|
||||
country = item.get("country")
|
||||
if country is None:
|
||||
if not required:
|
||||
return
|
||||
pprint(item)
|
||||
print(f"{source} missing country")
|
||||
sys.exit(-1)
|
||||
if not isinstance(country, str) or not agenda.get_country(country):
|
||||
pprint(item)
|
||||
print(f"{source} has invalid country {country!r}")
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def get_coords(item: agenda.types.StrDict) -> LatLon | None:
|
||||
"""Return latitude/longitude tuple when present."""
|
||||
if "latitude" in item and "longitude" in item:
|
||||
|
|
@ -267,6 +284,8 @@ def check_conferences() -> None:
|
|||
print(f"currency {conf.currency!r} not in {currencies!r}")
|
||||
sys.exit(-1)
|
||||
|
||||
check_country_code(conf_data, "conference", required=False)
|
||||
|
||||
current_start = normalize_datetime(conf_data["start"])
|
||||
if prev_start and current_start < prev_start:
|
||||
assert prev_conf_data is not None
|
||||
|
|
@ -290,6 +309,11 @@ def check_events() -> None:
|
|||
last_year = today - timedelta(days=365)
|
||||
next_year = today + timedelta(days=2 * 365)
|
||||
|
||||
filepath = os.path.join(data_dir, "events.yaml")
|
||||
events_data = yaml.safe_load(open(filepath, "r"))
|
||||
for event in events_data:
|
||||
check_country_code(event, "event", required=False)
|
||||
|
||||
events = agenda.events_yaml.read(data_dir, last_year, next_year)
|
||||
print(len(events), "events")
|
||||
|
||||
|
|
@ -314,6 +338,7 @@ def check_accommodation() -> None:
|
|||
for stay in accommodation_list:
|
||||
try:
|
||||
assert all(field in stay for field in required_fields)
|
||||
check_country_code(stay, "accommodation")
|
||||
check_coordinates(stay)
|
||||
except AssertionError:
|
||||
pprint(stay)
|
||||
|
|
@ -347,8 +372,7 @@ def check_airports() -> None:
|
|||
)
|
||||
print(len(airports), "airports")
|
||||
for airport in airports.values():
|
||||
assert "country" in airport
|
||||
assert agenda.get_country(airport["country"])
|
||||
check_country_code(airport, "airport")
|
||||
|
||||
|
||||
def check_stations() -> None:
|
||||
|
|
@ -356,8 +380,31 @@ def check_stations() -> None:
|
|||
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"])
|
||||
check_country_code(station, "station")
|
||||
|
||||
|
||||
def check_ferry_terminals() -> None:
|
||||
"""Check ferry terminals."""
|
||||
terminals = agenda.travel.parse_yaml("ferry_terminals", data_dir)
|
||||
print(len(terminals), "ferry terminals")
|
||||
for terminal in terminals:
|
||||
check_country_code(terminal, "ferry terminal")
|
||||
|
||||
|
||||
def check_bus_stops() -> None:
|
||||
"""Check bus stops."""
|
||||
stops = agenda.travel.parse_yaml("bus_stops", data_dir)
|
||||
print(len(stops), "bus stops")
|
||||
for stop in stops:
|
||||
check_country_code(stop, "bus stop")
|
||||
|
||||
|
||||
def check_coach_stations() -> None:
|
||||
"""Check coach stations."""
|
||||
stations = agenda.travel.parse_yaml("coach_stations", data_dir)
|
||||
print(len(stations), "coach stations")
|
||||
for station in stations:
|
||||
check_country_code(station, "coach station")
|
||||
|
||||
|
||||
def check_ferries() -> None:
|
||||
|
|
@ -415,8 +462,8 @@ def check_buses() -> None:
|
|||
|
||||
def check_airlines() -> list[agenda.types.StrDict]:
|
||||
"""Check airlines."""
|
||||
airlines = typing.cast(
|
||||
list[agenda.types.StrDict], agenda.travel.parse_yaml("airlines", data_dir)
|
||||
airlines: list[agenda.types.StrDict] = agenda.travel.parse_yaml(
|
||||
"airlines", data_dir
|
||||
)
|
||||
print(len(airlines), "airlines")
|
||||
for airline in airlines:
|
||||
|
|
@ -450,6 +497,9 @@ def check() -> None:
|
|||
check_accommodation()
|
||||
check_airports()
|
||||
check_stations()
|
||||
check_ferry_terminals()
|
||||
check_bus_stops()
|
||||
check_coach_stations()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue