From 199eb82bcee732f5f59c097fc65c5a1dde166e49 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 8 Jan 2024 15:45:08 +0000 Subject: [PATCH] Add refresh option for Bristol waste schedule --- agenda/waste_schedule.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/agenda/waste_schedule.py b/agenda/waste_schedule.py index 4f4dade..3e3f253 100644 --- a/agenda/waste_schedule.py +++ b/agenda/waste_schedule.py @@ -104,7 +104,9 @@ def parse(root: lxml.html.HtmlElement) -> list[Event]: BristolSchedule = list[dict[str, typing.Any]] -async def get_bristol_data(data_dir: str, uprn: str) -> BristolSchedule: +async def get_bristol_data( + data_dir: str, uprn: str, refresh: bool = False +) -> BristolSchedule: """Get Bristol Waste schedule, with cache.""" now = datetime.now() waste_dir = os.path.join(data_dir, "waste") @@ -122,7 +124,7 @@ async def get_bristol_data(data_dir: str, uprn: str) -> BristolSchedule: json_data = json.load(open(os.path.join(waste_dir, recent_filename))) return typing.cast(BristolSchedule, json_data["data"]) - if existing and delta < timedelta(hours=ttl_hours): + if not refresh and existing and delta < timedelta(hours=ttl_hours): return get_from_recent() try: @@ -186,9 +188,11 @@ async def get_bristol_gov_uk_data(uprn: str) -> httpx.Response: return response -async def get_bristol_gov_uk(start_date: date, data_dir: str, uprn: str) -> list[Event]: +async def get_bristol_gov_uk( + start_date: date, data_dir: str, uprn: str, refresh: bool = False +) -> list[Event]: """Get waste collection schedule from Bristol City Council.""" - data = await get_bristol_data(data_dir, uprn) + data = await get_bristol_data(data_dir, uprn, refresh) by_date: defaultdict[date, list[str]] = defaultdict(list)