From bf5f7f22763b1da26a60096c68abd5afa9fbc727 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 8 Nov 2023 12:48:02 +0000 Subject: [PATCH] Move Christmas posting days into config file Closes: #14 --- agenda/data.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/agenda/data.py b/agenda/data.py index ca50927..7789d0c 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -37,8 +37,6 @@ here = dateutil.tz.tzlocal() next_us_presidential_election = date(2024, 11, 5) -xmas_last_posting_dates = {"first": date(2023, 12, 20), "second": date(2023, 12, 18)} - # deadline to file tax return # credit card expiry dates # morzine ski lifts @@ -163,6 +161,18 @@ def combine_holidays(events: list[Event]) -> list[Event]: return list(combined.values()) +def xmas_last_posting(config: configparser.ConfigParser) -> list[Event]: + """Last posting days for Christmas.""" + return [ + Event( + name=f"xmas_last_{key}", + date=date.fromisoformat(config["xmas_last_posting_dates"][key]), + url="https://www.postoffice.co.uk/last-posting-dates", + ) + for key in ("first", "second") + ] + + async def get_data(now: datetime) -> typing.Mapping[str, str | object]: """Get data to display on agenda dashboard.""" config_filename = os.path.join(os.path.dirname(__file__), "..", "config") @@ -215,7 +225,6 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: "mothers_day": uk_holiday.get_mothers_day(today), "fathers_day": uk_holiday.get_fathers_day(today), "uk_financial_year_end": uk_financial_year_end(last_year, next_year), - "xmas_last_posting_dates": xmas_last_posting_dates, "gwr_advance_tickets": gwr_advance_tickets, "critical_mass": critical_mass(last_year, next_year), "market": ( @@ -226,7 +235,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: "rockets": rockets, } - skip = {"now", "gbpusd", "rockets", "stock_markets", "xmas_last_posting_dates"} + skip = {"now", "gbpusd", "rockets", "stock_markets"} events: list[Event] = [] for key, value in reply.items(): if key in skip: @@ -242,15 +251,6 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: reply["sunrise"] = sun.sunrise(observer) reply["sunset"] = sun.sunset(observer) - for key, value in xmas_last_posting_dates.items(): - events.append( - Event( - name=f"xmas_last_{key}", - date=value, - url="https://www.postoffice.co.uk/last-posting-dates", - ) - ) - events += combine_holidays(bank_holiday + get_us_holidays(last_year, next_year)) my_data = config["data"]["personal-data"] @@ -259,6 +259,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: events += travel.all_events(config["data"]["personal-data"]) events += conference.get_list(os.path.join(my_data, "conferences.yaml")) events += backwell_bins + bristol_bins + events += xmas_last_posting(config) events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml"))