diff --git a/agenda/data.py b/agenda/data.py index 462b3d9..056f508 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -110,6 +110,24 @@ async def time_function( return name, result, end_time - start_time, exception +def hide_markets_while_away( + events: list[Event], accommodation_events: list[Event] +) -> None: + """Hide markets that happen while away.""" + optional = [ + e + for e in events + if e.name == "market" or (e.title and "LHG Run Club" in e.title) + ] + going = [e for e in events if e.going] + + overlapping_markets = find_events_during_stay( + accommodation_events + going, optional + ) + for market in overlapping_markets: + events.remove(market) + + async def get_data( now: datetime, config: flask.config.Config ) -> typing.Mapping[str, str | object]: @@ -210,19 +228,8 @@ async def get_data( events += hn.whoishiring(last_year, next_year) events += carnival.rio_carnival_events(last_year, next_year) - # hide markets that happen while away - optional = [ - e - for e in events - if e.name == "market" or (e.title and "LHG Run Club" in e.title) - ] - going = [e for e in events if e.going] - - overlapping_markets = find_events_during_stay( - accommodation_events + going, optional - ) - for market in overlapping_markets: - events.remove(market) + if config["HIDE_MARKETS_WHILE_AWAY"]: + hide_markets_while_away(events, accommodation_events) for launch in rockets: dt = None