From 3aeb2fe467e371ffe032cb8e14ec08e210cd56cf Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 21 Oct 2023 12:08:20 +0100 Subject: [PATCH] Read YAML filepaths from config --- agenda/__init__.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index ffabfe2..7aa18ed 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -303,12 +303,10 @@ def next_birthday(from_date: date, birth_date: date) -> tuple[date, int]: return next_birthday_date, age_at_next_birthday -def get_birthdays(from_date: date, config: configparser.ConfigParser) -> list[Event]: +def get_birthdays(from_date: date, filepath: str) -> list[Event]: """Get birthdays from config.""" - filename = config["data"]["entities"] - events = [] - with open(filename) as f: + with open(filepath) as f: entities = yaml.safe_load(f) for entity in entities: @@ -325,12 +323,10 @@ def get_birthdays(from_date: date, config: configparser.ConfigParser) -> list[Ev return events -def get_travel(from_date: date, config: configparser.ConfigParser) -> list[Event]: +def get_travel(from_date: date, filepath: str) -> list[Event]: """Get birthdays from config.""" - filename = config["data"]["travel"] - events = [] - with open(filename) as f: + with open(filepath) as f: items = yaml.safe_load(f) for item in items: @@ -414,9 +410,9 @@ def get_data(now: datetime) -> dict[str, str | object]: for key, value in xmas_last_posting_dates.items(): events.append(Event(name=f"xmas_last_{key}", date=value)) - events += get_birthdays(today, config) - events += get_travel(today, config) - events += get_conferences(today, "conferences.yaml") + events += get_birthdays(today, config["data"]["entities"]) + events += get_travel(today, config["data"]["travel"]) + events += get_conferences(today, config["data"]["conferences"]) events += waste_collection_events() next_up_series = Event(