Show upcoming travel include travel and accommodation

Closes: #15
This commit is contained in:
Edward Betts 2023-10-21 11:52:46 +01:00
parent aafd37ab5a
commit 2e785579f3

View file

@ -325,6 +325,46 @@ def get_birthdays(from_date: date, config: configparser.ConfigParser) -> list[Ev
return events return events
def get_travel(from_date: date, config: configparser.ConfigParser) -> list[Event]:
"""Get birthdays from config."""
filename = config["data"]["travel"]
events = []
with open(filename) as f:
items = yaml.safe_load(f)
for item in items:
if item["type"] == "accommodation":
title = (
f'{item["location"]} Airbnb'
if item["operator"] == "airbnb"
else item["name"]
)
from_date = item["from"]
to_date = item["to"]
nights = (to_date - from_date).days
night_str = f"{nights} nights" if nights != 1 else "1 night"
checkin = Event(
date=from_date,
name="accommodation",
title=f"check-in {title} ({night_str})",
)
checkout = Event(
date=to_date, name="accommodation", title="check-out " + title
)
events += [checkin, checkout]
continue
if item["type"] == "transport":
event = Event(
date=datetime.fromisoformat(item["depart"]).date(),
name="transport",
title=f'{item["transport_type"]} from {item["from"]} to {item["to"]}',
)
events.append(event)
return events
def waste_collection_events() -> list[Event]: def waste_collection_events() -> list[Event]:
"""Waste colllection events.""" """Waste colllection events."""
postcode = "BS48 3HG" postcode = "BS48 3HG"
@ -375,6 +415,7 @@ def get_data(now: datetime) -> dict[str, str | object]:
events.append(Event(name=f"xmas_last_{key}", date=value)) events.append(Event(name=f"xmas_last_{key}", date=value))
events += get_birthdays(today, config) events += get_birthdays(today, config)
events += get_travel(today, config)
events += get_conferences(today, "conferences.yaml") events += get_conferences(today, "conferences.yaml")
events += waste_collection_events() events += waste_collection_events()