Compare commits
No commits in common. "796edef75ccf30324483ce29aac5904245e20bda" and "22be45a6a3bd15fbba44f4ebc4cd4cc82549eb9d" have entirely different histories.
796edef75c
...
22be45a6a3
|
@ -136,17 +136,6 @@ async def bristol_waste_collection_events(
|
|||
|
||||
def combine_holidays(holidays: list[Holiday]) -> list[Event]:
|
||||
"""Combine UK and US holidays with the same date and title."""
|
||||
|
||||
all_countries = {h.country for h in holidays}
|
||||
|
||||
standard_name = {
|
||||
(1, 1): "New Year's Day",
|
||||
(1, 6): "Epiphany",
|
||||
(12, 8): "Immaculate conception",
|
||||
(12, 25): "Christmas Day",
|
||||
(12, 26): "Boxing Day",
|
||||
}
|
||||
|
||||
combined: collections.defaultdict[
|
||||
tuple[date, str], set[str]
|
||||
] = collections.defaultdict(set)
|
||||
|
@ -154,21 +143,12 @@ def combine_holidays(holidays: list[Holiday]) -> list[Event]:
|
|||
for h in holidays:
|
||||
assert isinstance(h.name, str) and isinstance(h.date, date)
|
||||
|
||||
event_key = (h.date, standard_name.get((h.date.month, h.date.day), h.name))
|
||||
event_key = (h.date, h.name)
|
||||
combined[event_key].add(h.country)
|
||||
|
||||
events: list[Event] = []
|
||||
for (d, name), countries in combined.items():
|
||||
if len(countries) == len(all_countries):
|
||||
country_list = ""
|
||||
elif len(countries) < len(all_countries) / 2:
|
||||
country_list = ", ".join(sorted(country.upper() for country in countries))
|
||||
else:
|
||||
country_list = "not " + ", ".join(
|
||||
sorted(country.upper() for country in all_countries - set(countries))
|
||||
)
|
||||
|
||||
title = f"{name} ({country_list})"
|
||||
title = f'{name} ({", ".join(country.upper() for country in countries)})'
|
||||
e = Event(name="holiday", date=d, title=title)
|
||||
events.append(e)
|
||||
|
||||
|
|
Loading…
Reference in a new issue