diff --git a/agenda/data.py b/agenda/data.py index 4bbd76f..c1f6f4d 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -182,8 +182,11 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData: plus_365 = now + timedelta(days=365) t0 = time() + offline_mode = bool(config.get("OFFLINE_MODE")) result_list = await asyncio.gather( - time_function("gwr_advance_tickets", gwr.advance_ticket_date, data_dir), + time_function( + "gwr_advance_tickets", gwr.advance_ticket_date, data_dir, offline_mode + ), time_function( "backwell_bins", n_somerset_waste_collection_events, diff --git a/agenda/gwr.py b/agenda/gwr.py index 750af90..cc7e968 100644 --- a/agenda/gwr.py +++ b/agenda/gwr.py @@ -48,11 +48,13 @@ def extract_weekday_date(html: str) -> date | None: return None -async def advance_tickets_page_html(data_dir: str, ttl: int = 60 * 60 * 6) -> str: +async def advance_tickets_page_html( + data_dir: str, ttl: int = 60 * 60 * 6, force_cache: bool = False +) -> str: """Get advance-tickets web page HTML with cache.""" filename = os.path.join(data_dir, "advance-tickets.html") mtime = os.path.getmtime(filename) if os.path.exists(filename) else 0 - if (time() - mtime) < ttl: # use cache + if force_cache or (time() - mtime) < ttl: # use cache return open(filename).read() async with httpx.AsyncClient() as client: r = await client.get(url) @@ -61,7 +63,7 @@ async def advance_tickets_page_html(data_dir: str, ttl: int = 60 * 60 * 6) -> st return html -async def advance_ticket_date(data_dir: str) -> date | None: +async def advance_ticket_date(data_dir: str, force_cache: bool = False) -> date | None: """Get GWR advance tickets date with cache.""" - html = await advance_tickets_page_html(data_dir) + html = await advance_tickets_page_html(data_dir, force_cache=force_cache) return extract_weekday_date(html)