From a9c71afb9765e8a319ae0f9e5bdd1e04c46c6eff Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 5 Nov 2023 13:39:40 +0000 Subject: [PATCH] Simplify code for accommodation --- agenda/__init__.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index 05d9ee0..a854859 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -251,29 +251,23 @@ def as_date(d: date | datetime) -> date: 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.""" - events = [] with open(filepath) as f: - items = yaml.safe_load(f) - - for item in items: - title = ( - f'{item["location"]} Airbnb' - if item["operator"] == "airbnb" - 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"), - ) - events.append(e) - return events + return [ + Event( + date=item["from"], + end_date=item["to"], + name="accommodation", + title=( + f'{item["location"]} Airbnb' + if item["operator"] == "airbnb" + else item["name"] + ), + url=item.get("url"), + ) + for item in yaml.safe_load(f) + ] 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"] 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 += conference.get_list(os.path.join(my_data, "conferences.yaml")) events += waste_collection_events() + bristol_waste_collection_events(today)