Validate maximum trip length
This commit is contained in:
parent
3747e83ade
commit
ea80166229
1 changed files with 19 additions and 0 deletions
|
|
@ -25,6 +25,7 @@ data_dir = config.PERSONAL_DATA
|
||||||
currencies = set(config.CURRENCIES + ["GBP"])
|
currencies = set(config.CURRENCIES + ["GBP"])
|
||||||
|
|
||||||
LatLon = Tuple[float, float]
|
LatLon = Tuple[float, float]
|
||||||
|
MAX_TRIP_NIGHTS = 60
|
||||||
|
|
||||||
|
|
||||||
def check_currency(item: agenda.types.StrDict) -> None:
|
def check_currency(item: agenda.types.StrDict) -> None:
|
||||||
|
|
@ -102,6 +103,22 @@ def ranges_overlap(
|
||||||
return start_a < end_b and start_b < end_a
|
return start_a < end_b and start_b < end_a
|
||||||
|
|
||||||
|
|
||||||
|
def check_trip_duration(trip: agenda.types.Trip) -> None:
|
||||||
|
"""Check trip duration is within the expected maximum."""
|
||||||
|
if trip.end is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
nights = (trip.end - trip.start).days
|
||||||
|
if nights <= MAX_TRIP_NIGHTS:
|
||||||
|
return
|
||||||
|
|
||||||
|
url = f"https://edwardbetts.com/agenda/trip/{trip.start.isoformat()}"
|
||||||
|
print(f"Trip is too long: {url}")
|
||||||
|
print(f" {trip.title}")
|
||||||
|
print(f" {trip.start.isoformat()} to {trip.end.isoformat()}: {nights} nights")
|
||||||
|
assert False, f"Trip is {nights} nights; maximum is {MAX_TRIP_NIGHTS}"
|
||||||
|
|
||||||
|
|
||||||
def check_trips() -> None:
|
def check_trips() -> None:
|
||||||
"""Check trips and ensure they are in chronological order."""
|
"""Check trips and ensure they are in chronological order."""
|
||||||
filepath = os.path.join(data_dir, "trips.yaml")
|
filepath = os.path.join(data_dir, "trips.yaml")
|
||||||
|
|
@ -130,6 +147,8 @@ def check_trips() -> None:
|
||||||
print(len(trip_list), "trips")
|
print(len(trip_list), "trips")
|
||||||
|
|
||||||
for trip in trip_list:
|
for trip in trip_list:
|
||||||
|
check_trip_duration(trip)
|
||||||
|
|
||||||
if not trip.accommodation or not trip.conferences:
|
if not trip.accommodation or not trip.conferences:
|
||||||
continue
|
continue
|
||||||
accommodation_entries: list[
|
accommodation_entries: list[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue