Include black friday and cyber monday

Closes: #56
This commit is contained in:
Edward Betts 2023-11-05 17:37:48 +00:00
parent cc47762e9d
commit 592710a28c

View file

@ -214,14 +214,31 @@ def stock_markets() -> list[str]:
return reply
def get_us_holidays(input_date: date) -> list[Event]:
def get_us_holidays(start_date: date, end_date: date) -> list[Event]:
"""Date and name of next US holiday."""
hols = holidays.UnitedStates(years=[input_date.year, input_date.year + 1])
return [
Event(name="us_holiday", date=hol_date, title=title)
for hol_date, title in sorted(hols.items())
if hol_date >= input_date
]
found: 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)
for hol_date, title in hols.items()
if start_date < hol_date < end_date
]
extra = []
for e in found:
if e.title != "Thanksgiving":
continue
extra += [
Event(
name="us_holiday", date=e.date + timedelta(days=1), title="Black Friday"
),
Event(
name="us_holiday", date=e.date + timedelta(days=4), title="Cyber Monday"
),
]
return found + extra
def critical_mass(start_date: date, limit: int = 12) -> list[Event]:
@ -321,7 +338,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
"gbpusd": gbpusd,
"next_economist": economist.next_pub_date(today),
"bank_holiday": bank_holiday,
"us_holiday": get_us_holidays(today),
"us_holiday": get_us_holidays(last_year, next_year),
"next_us_presidential_election": next_us_presidential_election,
"stock_markets": stock_markets(),
"uk_clock_change": timezone_transition(