diff --git a/agenda/data.py b/agenda/data.py index de41eaf..3e6ea9e 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -105,7 +105,7 @@ def get_us_holidays(start_date: date, end_date: date) -> list[Event]: for year in range(start_date.year, end_date.year + 1): hols = holidays.UnitedStates(years=year) found += [ - Event(name="us_holiday", date=hol_date, title=title) + Event(name="us_holiday", date=hol_date, title=title.replace("'", "’")) for hol_date, title in hols.items() if start_date < hol_date < end_date ] @@ -164,6 +164,21 @@ async def bristol_waste_collection_events( return await waste_schedule.get_bristol_gov_uk(start_date, data_dir, uprn) +def combine_holidays(events: list[Event]) -> list[Event]: + combined: dict[tuple[date, str], Event] = {} + + for e in events: + assert isinstance(e.title, str) and isinstance(e.date, date) + event_key = (e.date, e.title) + combined[event_key] = ( + Event(name="bank_holiday", date=e.date, title=e.title + " (UK & US)") + if event_key in combined + else e + ) + + return list(combined.values()) + + 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") @@ -205,8 +220,6 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: "now": now, "gbpusd": gbpusd, "economist": economist.publication_dates(last_year, next_year), - "bank_holiday": bank_holiday, - "us_holiday": get_us_holidays(last_year, next_year), "next_us_presidential_election": next_us_presidential_election, "stock_markets": stock_market.open_and_close(), "uk_clock_change": timezone_transition( @@ -254,6 +267,8 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: ) ) + events += combine_holidays(bank_holiday + get_us_holidays(last_year, next_year)) + my_data = config["data"]["personal-data"] events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml")) events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml"))