Simplify code for accommodation

This commit is contained in:
Edward Betts 2023-11-05 13:39:40 +00:00
parent 2c9b97f0c2
commit a9c71afb97

View file

@ -251,29 +251,23 @@ def as_date(d: date | datetime) -> date:
return d.date() if isinstance(d, datetime) else d return d.date() if isinstance(d, datetime) else d
def get_accommodation(from_date: date, filepath: str) -> list[Event]: def get_accommodation(filepath: str) -> list[Event]:
"""Get birthdays from config.""" """Get birthdays from config."""
events = []
with open(filepath) as f: with open(filepath) as f:
items = yaml.safe_load(f) return [
Event(
for item in items: date=item["from"],
title = ( end_date=item["to"],
name="accommodation",
title=(
f'{item["location"]} Airbnb' f'{item["location"]} Airbnb'
if item["operator"] == "airbnb" if item["operator"] == "airbnb"
else item["name"] else item["name"]
) ),
from_date = item["from"]
to_date = item["to"]
e = Event(
date=from_date,
end_date=to_date,
name="accommodation",
title=title,
url=item.get("url"), url=item.get("url"),
) )
events.append(e) for item in yaml.safe_load(f)
return events ]
def waste_collection_events() -> list[Event]: def waste_collection_events() -> list[Event]:
@ -346,7 +340,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
my_data = config["data"]["personal-data"] my_data = config["data"]["personal-data"]
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml")) events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml")) events += get_accommodation(os.path.join(my_data, "accommodation.yaml"))
events += travel.all_events(today, config["data"]["personal-data"]) events += travel.all_events(today, config["data"]["personal-data"])
events += conference.get_list(os.path.join(my_data, "conferences.yaml")) events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
events += waste_collection_events() + bristol_waste_collection_events(today) events += waste_collection_events() + bristol_waste_collection_events(today)