Check for unknown currencies during validation
This commit is contained in:
parent
67b1adf956
commit
6d1b01485a
|
@ -2,6 +2,7 @@
|
||||||
"""Load YAML data to ensure validity."""
|
"""Load YAML data to ensure validity."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import typing
|
import typing
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
|
@ -18,6 +19,18 @@ import agenda.types
|
||||||
config = __import__("config.default", fromlist=[""])
|
config = __import__("config.default", fromlist=[""])
|
||||||
data_dir = config.PERSONAL_DATA
|
data_dir = config.PERSONAL_DATA
|
||||||
|
|
||||||
|
currencies = set(config.CURRENCIES + ["GBP"])
|
||||||
|
|
||||||
|
|
||||||
|
def check_currency(item: agenda.types.StrDict) -> None:
|
||||||
|
"""Throw error if currency is not in config."""
|
||||||
|
currency = item.get("currency")
|
||||||
|
if not currency or currency in currencies:
|
||||||
|
return None
|
||||||
|
pprint(item)
|
||||||
|
print(f"currency {currency!r} not in {currencies!r}")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
def check_trips() -> None:
|
def check_trips() -> None:
|
||||||
"""Check trips."""
|
"""Check trips."""
|
||||||
|
@ -34,6 +47,10 @@ def check_flights(airlines: set[str]) -> None:
|
||||||
bookings = agenda.travel.parse_yaml("flights", data_dir)
|
bookings = agenda.travel.parse_yaml("flights", data_dir)
|
||||||
for booking in bookings:
|
for booking in bookings:
|
||||||
assert all(flight["airline"] in airlines for flight in booking["flights"])
|
assert all(flight["airline"] in airlines for flight in booking["flights"])
|
||||||
|
|
||||||
|
for booking in bookings:
|
||||||
|
check_currency(booking)
|
||||||
|
|
||||||
print(len(bookings), "flights")
|
print(len(bookings), "flights")
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +62,18 @@ def check_trains() -> None:
|
||||||
|
|
||||||
def check_conferences() -> None:
|
def check_conferences() -> None:
|
||||||
"""Check conferences."""
|
"""Check conferences."""
|
||||||
conferences = agenda.conference.get_list(os.path.join(data_dir, "conferences.yaml"))
|
filepath = os.path.join(data_dir, "conferences.yaml")
|
||||||
|
conferences = [
|
||||||
|
agenda.conference.Conference(**conf)
|
||||||
|
for conf in yaml.safe_load(open(filepath, "r"))
|
||||||
|
]
|
||||||
|
for conf in conferences:
|
||||||
|
if not conf.currency or conf.currency in currencies:
|
||||||
|
continue
|
||||||
|
pprint(conf)
|
||||||
|
print(f"currency {conf.currency!r} not in {currencies!r}")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
print(len(conferences), "conferences")
|
print(len(conferences), "conferences")
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +110,8 @@ def check_accommodation() -> None:
|
||||||
pprint(stay)
|
pprint(stay)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
check_currency(stay)
|
||||||
|
|
||||||
print(len(accommodation_list), "stays")
|
print(len(accommodation_list), "stays")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue