Compare commits
No commits in common. "cc47762e9da6681ad9fb3a41aa10d5470efdf8ee" and "4f2b9f7fae73004b3dc0417b8bb4b0eddd4b9250" have entirely different histories.
cc47762e9d
...
4f2b9f7fae
|
@ -107,16 +107,12 @@ def next_uk_fathers_day(input_date: date) -> date:
|
||||||
return fathers_day
|
return fathers_day
|
||||||
|
|
||||||
|
|
||||||
def timezone_transition(
|
def get_next_timezone_transition(from_dt: datetime, tz_name: str) -> date:
|
||||||
start_dt: datetime, end_dt: datetime, key: str, tz_name: str
|
"""Datetime of the next time the clocks change."""
|
||||||
) -> list[Event]:
|
|
||||||
"""Clocks changes."""
|
|
||||||
tz = pytz.timezone(tz_name)
|
tz = pytz.timezone(tz_name)
|
||||||
return [
|
dt = next(t for t in tz._utc_transition_times if t > from_dt)
|
||||||
Event(name=key, date=pytz.utc.localize(t).astimezone(tz))
|
|
||||||
for t in tz._utc_transition_times # type: ignore
|
return typing.cast(date, dt.date())
|
||||||
if start_dt <= t <= end_dt
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
async def get_next_bank_holiday(input_date: date) -> list[Event]:
|
async def get_next_bank_holiday(input_date: date) -> list[Event]:
|
||||||
|
@ -124,7 +120,7 @@ async def get_next_bank_holiday(input_date: date) -> list[Event]:
|
||||||
url = "https://www.gov.uk/bank-holidays.json"
|
url = "https://www.gov.uk/bank-holidays.json"
|
||||||
filename = os.path.join(data_dir, "bank-holidays.json")
|
filename = os.path.join(data_dir, "bank-holidays.json")
|
||||||
mtime = os.path.getmtime(filename)
|
mtime = os.path.getmtime(filename)
|
||||||
if (unixtime() - mtime) > 60 * 60 * 6: # six hours
|
if (unixtime() - mtime) > 3600: # one hour
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(url)
|
r = await client.get(url)
|
||||||
open(filename, "w").write(r.text)
|
open(filename, "w").write(r.text)
|
||||||
|
@ -301,9 +297,6 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
||||||
last_year = today - timedelta(days=365)
|
last_year = today - timedelta(days=365)
|
||||||
next_year = today + timedelta(days=365)
|
next_year = today + timedelta(days=365)
|
||||||
|
|
||||||
minus_365 = now - timedelta(days=365)
|
|
||||||
plus_365 = now + timedelta(days=365)
|
|
||||||
|
|
||||||
(
|
(
|
||||||
gbpusd,
|
gbpusd,
|
||||||
gwr_advance_tickets,
|
gwr_advance_tickets,
|
||||||
|
@ -324,12 +317,8 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
|
||||||
"us_holiday": get_us_holidays(today),
|
"us_holiday": get_us_holidays(today),
|
||||||
"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": get_next_timezone_transition(now, "Europe/London"),
|
||||||
minus_365, plus_365, "uk_clock_change", "Europe/London"
|
"us_clock_change": get_next_timezone_transition(now, "America/New_York"),
|
||||||
),
|
|
||||||
"us_clock_change": timezone_transition(
|
|
||||||
minus_365, plus_365, "us_clock_change", "America/New_York"
|
|
||||||
),
|
|
||||||
"mothers_day": next_uk_mothers_day(today),
|
"mothers_day": next_uk_mothers_day(today),
|
||||||
"fathers_day": next_uk_fathers_day(today),
|
"fathers_day": next_uk_fathers_day(today),
|
||||||
"uk_financial_year_end": uk_financial_year_end(today),
|
"uk_financial_year_end": uk_financial_year_end(today),
|
||||||
|
|
Loading…
Reference in a new issue