From 2cc4d553bfa2a21eb66cb565275b85622acc911f Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 9 Dec 2023 11:39:33 +0000 Subject: [PATCH] Add public holidays for other European countries Closes: #82 --- agenda/data.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/agenda/data.py b/agenda/data.py index 92efe09..3302819 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -58,11 +58,11 @@ def timezone_transition( ] -def get_us_holidays(start_date: date, end_date: date) -> list[Event]: - """Date and name of next US holiday.""" +def us_holidays(start_date: date, end_date: date) -> list[Event]: + """Get US holidays.""" found: list[Event] = [] for year in range(start_date.year, end_date.year + 1): - hols = holidays.UnitedStates(years=year) + hols = holidays.country_holidays("US", years=year, language="en") found += [ Event(name="us_holiday", date=hol_date, title=title.replace("'", "’")) for hol_date, title in hols.items() @@ -85,6 +85,24 @@ def get_us_holidays(start_date: date, end_date: date) -> list[Event]: return found + extra +def get_holidays(country: str, start_date: date, end_date: date) -> list[Event]: + """Get holidays.""" + found: list[Event] = [] + for year in range(start_date.year, end_date.year + 1): + hols = holidays.country_holidays(country.upper(), years=year, language="en") + found += [ + Event( + name=country.lower() + "_holiday", + date=hol_date, + title=f"{title} ({country.upper()})", + ) + for hol_date, title in hols.items() + if start_date < hol_date < end_date + ] + + return found + + def dates_from_rrule( rrule: str, start: date, end: date ) -> typing.Sequence[datetime | date]: @@ -239,7 +257,9 @@ async def get_data( if gwr_advance_tickets: events.append(Event(name="gwr_advance_tickets", date=gwr_advance_tickets)) - events += combine_holidays(bank_holiday + get_us_holidays(last_year, next_year)) + events += combine_holidays(bank_holiday + us_holidays(last_year, next_year)) + for country in "be", "de", "fr", "nl": + events += get_holidays(country, last_year, next_year) events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml")) events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml")) events += travel.all_events(my_data)