diff --git a/agenda/bristol_waste.py b/agenda/bristol_waste.py index db8f80f..cab155f 100644 --- a/agenda/bristol_waste.py +++ b/agenda/bristol_waste.py @@ -17,10 +17,12 @@ ttl_hours = 12 BristolSchedule = list[dict[str, typing.Any]] -async def get(start_date: date, data_dir: str, uprn: str, cache: str) -> list[Event]: +async def get( + start_date: date, data_dir: str, uprn: str, refresh: bool = False +) -> list[Event]: """Get waste collection schedule from Bristol City Council.""" by_date: defaultdict[date, list[str]] = defaultdict(list) - for item in await get_data(data_dir, uprn, cache): + for item in await get_data(data_dir, uprn, refresh): service = get_service(item) for d in collections(item): if d < start_date and service not in by_date[d]: @@ -32,7 +34,7 @@ async def get(start_date: date, data_dir: str, uprn: str, cache: str) -> list[Ev ] -async def get_data(data_dir: str, uprn: str, cache: str) -> BristolSchedule: +async def get_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") @@ -50,11 +52,7 @@ async def get_data(data_dir: str, uprn: str, cache: str) -> BristolSchedule: json_data = json.load(open(os.path.join(waste_dir, recent_filename))) return typing.cast(BristolSchedule, json_data["data"]) - if ( - cache != "refresh" - and existing - and (cache == "force" or delta < timedelta(hours=ttl_hours)) - ): + if not refresh and existing and delta < timedelta(hours=ttl_hours): return get_from_recent() try: diff --git a/agenda/data.py b/agenda/data.py index 7054a72..c1f6f4d 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -62,21 +62,20 @@ def timezone_transition( async def n_somerset_waste_collection_events( - data_dir: str, postcode: str, uprn: str, force_cache: bool = False + data_dir: str, postcode: str, uprn: str ) -> list[Event]: """Waste colllection events.""" - html = await n_somerset_waste.get_html(data_dir, postcode, uprn, force_cache) + html = await n_somerset_waste.get_html(data_dir, postcode, uprn) root = lxml.html.fromstring(html) events = n_somerset_waste.parse(root) return events async def bristol_waste_collection_events( - data_dir: str, start_date: date, uprn: str, force_cache: bool = False + data_dir: str, start_date: date, uprn: str ) -> list[Event]: """Waste colllection events.""" - cache = "force" if force_cache else "recent" - return await bristol_waste.get(start_date, data_dir, uprn, cache) + return await bristol_waste.get(start_date, data_dir, uprn) def find_events_during_stay( @@ -194,7 +193,6 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData: data_dir, config["BACKWELL_POSTCODE"], config["BACKWELL_UPRN"], - offline_mode, ), time_function( "bristol_bins", @@ -202,7 +200,6 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData: data_dir, today, config["BRISTOL_UPRN"], - offline_mode, ), ) rockets = thespacedevs.read_cached_launches(rocket_dir) diff --git a/agenda/n_somerset_waste.py b/agenda/n_somerset_waste.py index 2d9cddd..16b168a 100644 --- a/agenda/n_somerset_waste.py +++ b/agenda/n_somerset_waste.py @@ -15,9 +15,7 @@ from .utils import make_waste_dir ttl_hours = 12 -async def get_html( - data_dir: str, postcode: str, uprn: str, force_cache: bool = False -) -> str: +async def get_html(data_dir: str, postcode: str, uprn: str) -> str: """Get waste schedule.""" now = datetime.now() waste_dir = os.path.join(data_dir, "waste") @@ -31,7 +29,7 @@ async def get_html( recent = datetime.strptime(recent_filename, "%Y-%m-%d_%H:%M.html") delta = now - recent - if existing and (force_cache or delta < timedelta(hours=ttl_hours)): + if existing and delta < timedelta(hours=ttl_hours): return open(os.path.join(waste_dir, recent_filename)).read() now_str = now.strftime("%Y-%m-%d_%H:%M") diff --git a/update.py b/update.py index a22b169..3216ed4 100755 --- a/update.py +++ b/update.py @@ -40,10 +40,7 @@ async def update_bristol_bins(config: flask.config.Config) -> None: """Update waste schedule from Bristol City Council.""" t0 = time() events = await agenda.bristol_waste.get( - date.today(), - config["DATA_DIR"], - config["BRISTOL_UPRN"], - cache="refresh", + date.today(), config["DATA_DIR"], config["BRISTOL_UPRN"], refresh=True ) time_taken = time() - t0 if not sys.stdin.isatty(): diff --git a/validate_yaml.py b/validate_yaml.py index 818840d..68df0f9 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -2,7 +2,6 @@ """Load YAML data to ensure validity.""" import os -import sys import typing from datetime import date, timedelta @@ -19,18 +18,6 @@ import agenda.types config = __import__("config.default", fromlist=[""]) data_dir = config.PERSONAL_DATA -currencies = set(config.CURRENCIES + ["GBP"]) - - -def check_currency(item: agenda.types.StrDict) -> None: - """Throw error if currency is not in config.""" - currency = item.get("currency") - if not currency or currency in currencies: - return None - pprint(item) - print(f"currency {currency!r} not in {currencies!r}") - sys.exit(-1) - def check_trips() -> None: """Check trips.""" @@ -47,10 +34,6 @@ def check_flights(airlines: set[str]) -> None: bookings = agenda.travel.parse_yaml("flights", data_dir) for booking in bookings: assert all(flight["airline"] in airlines for flight in booking["flights"]) - - for booking in bookings: - check_currency(booking) - print(len(bookings), "flights") @@ -62,18 +45,7 @@ def check_trains() -> None: def check_conferences() -> None: """Check conferences.""" - filepath = os.path.join(data_dir, "conferences.yaml") - conferences = [ - agenda.conference.Conference(**conf) - for conf in yaml.safe_load(open(filepath, "r")) - ] - for conf in conferences: - if not conf.currency or conf.currency in currencies: - continue - pprint(conf) - print(f"currency {conf.currency!r} not in {currencies!r}") - sys.exit(-1) - + conferences = agenda.conference.get_list(os.path.join(data_dir, "conferences.yaml")) print(len(conferences), "conferences") @@ -110,8 +82,6 @@ def check_accommodation() -> None: pprint(stay) raise - check_currency(stay) - print(len(accommodation_list), "stays")