Compare commits

..

2 commits

Author SHA1 Message Date
Edward Betts bda05d214c Show more bank holidays in the past 2023-11-05 21:30:26 +00:00
Edward Betts c3c1659661 Add docstring 2023-11-05 21:29:59 +00:00
2 changed files with 5 additions and 7 deletions

View file

@ -119,7 +119,7 @@ def timezone_transition(
]
async def get_next_bank_holiday(input_date: date) -> list[Event]:
async def get_next_bank_holiday(start_date: date, end_date: date) -> list[Event]:
"""Date and name of the next UK bank holiday."""
url = "https://www.gov.uk/bank-holidays.json"
filename = os.path.join(data_dir, "bank-holidays.json")
@ -129,15 +129,13 @@ async def get_next_bank_holiday(input_date: date) -> list[Event]:
r = await client.get(url)
open(filename, "w").write(r.text)
year_later = input_date + timedelta(days=365)
events = json.load(open(filename))["england-and-wales"]["events"]
hols: list[Event] = []
for event in events:
event_date = datetime.strptime(event["date"], "%Y-%m-%d").date()
if event_date < input_date:
if event_date < start_date:
continue
if event_date > year_later:
if event_date > end_date:
break
hols.append(Event(name="bank_holiday", date=event_date, title=event["title"]))
@ -329,7 +327,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]:
) = await asyncio.gather(
fx.get_gbpusd(config),
gwr.advance_ticket_date(data_dir),
get_next_bank_holiday(today),
get_next_bank_holiday(last_year, next_year),
thespacedevs.get_launches(rocket_dir, limit=40),
)

View file

@ -1,4 +1,4 @@
#!/usr/bin/python3
"""Waste collection schedules."""
import json
import os