parent
cc47762e9d
commit
592710a28c
|
@ -214,15 +214,32 @@ def stock_markets() -> list[str]:
|
||||||
return reply
|
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."""
|
"""Date and name of next US holiday."""
|
||||||
hols = holidays.UnitedStates(years=[input_date.year, input_date.year + 1])
|
found: list[Event] = []
|
||||||
return [
|
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)
|
||||||
for hol_date, title in sorted(hols.items())
|
for hol_date, title in hols.items()
|
||||||
if hol_date >= input_date
|
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]:
|
def critical_mass(start_date: date, limit: int = 12) -> list[Event]:
|
||||||
"""Future dates for Critical Mass."""
|
"""Future dates for Critical Mass."""
|
||||||
|
@ -321,7 +338,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
||||||
"gbpusd": gbpusd,
|
"gbpusd": gbpusd,
|
||||||
"next_economist": economist.next_pub_date(today),
|
"next_economist": economist.next_pub_date(today),
|
||||||
"bank_holiday": bank_holiday,
|
"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,
|
"next_us_presidential_election": next_us_presidential_election,
|
||||||
"stock_markets": stock_markets(),
|
"stock_markets": stock_markets(),
|
||||||
"uk_clock_change": timezone_transition(
|
"uk_clock_change": timezone_transition(
|
||||||
|
|
Loading…
Reference in a new issue