Creating a new entity called a trip. This will group together any travel accommodation and conferences that happen together on one trip. A trip is assumed to start when leaving home and finish when returning home. The start date of a trip in is the trip ID. The date is written in ISO format. This assumes there cannot be multiple trips one one day. This assumption might be wrong, for example a morning day trip by rail, then another trip starts in the afternoon. I can change my choice of using dates as trip IDs if that happens. Sometimes during the planning of a trip the start date is unknown. For now we make up a start date, we can always change it later. If we use the start date in URLs then the URLs will change. Might need to keep a file of redirects, or could think of a different style of identifier. Trip ID have been added to accommodation, conferences, trains and flights. Later there will be a trips.yaml with notes about each trip.
34 lines
900 B
Python
34 lines
900 B
Python
"""Agenda functions."""
|
|
|
|
from datetime import date, datetime, time
|
|
|
|
import pycountry
|
|
import pytz
|
|
|
|
uk_tz = pytz.timezone("Europe/London")
|
|
|
|
|
|
def uk_time(d: date, t: time) -> datetime:
|
|
"""Combine time and date for UK timezone."""
|
|
return uk_tz.localize(datetime.combine(d, t))
|
|
|
|
|
|
def format_list_with_ampersand(items: list[str]) -> str:
|
|
"""Join a list of strings with commas and an ampersand."""
|
|
if len(items) > 1:
|
|
return ", ".join(items[:-1]) + " & " + items[-1]
|
|
elif items:
|
|
return items[0]
|
|
return ""
|
|
|
|
|
|
def get_country(alpha_2: str) -> pycountry.db.Country | None:
|
|
"""Lookup country by alpha-2 country code."""
|
|
if not alpha_2:
|
|
return None
|
|
if alpha_2 == "xk":
|
|
return pycountry.db.Country(flag="\U0001F1FD\U0001F1F0", name="Kosovo")
|
|
|
|
country: pycountry.db.Country = pycountry.countries.get(alpha_2=alpha_2.upper())
|
|
return country
|