parent
9506e5e60e
commit
2cc4d553bf
|
@ -58,11 +58,11 @@ def timezone_transition(
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_us_holidays(start_date: date, end_date: date) -> list[Event]:
|
def us_holidays(start_date: date, end_date: date) -> list[Event]:
|
||||||
"""Date and name of next US holiday."""
|
"""Get US holidays."""
|
||||||
found: list[Event] = []
|
found: list[Event] = []
|
||||||
for year in range(start_date.year, end_date.year + 1):
|
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 += [
|
found += [
|
||||||
Event(name="us_holiday", date=hol_date, title=title.replace("'", "’"))
|
Event(name="us_holiday", date=hol_date, title=title.replace("'", "’"))
|
||||||
for hol_date, title in hols.items()
|
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
|
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(
|
def dates_from_rrule(
|
||||||
rrule: str, start: date, end: date
|
rrule: str, start: date, end: date
|
||||||
) -> typing.Sequence[datetime | date]:
|
) -> typing.Sequence[datetime | date]:
|
||||||
|
@ -239,7 +257,9 @@ async def get_data(
|
||||||
if gwr_advance_tickets:
|
if gwr_advance_tickets:
|
||||||
events.append(Event(name="gwr_advance_tickets", date=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 += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
|
||||||
events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml"))
|
events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml"))
|
||||||
events += travel.all_events(my_data)
|
events += travel.all_events(my_data)
|
||||||
|
|
Loading…
Reference in a new issue