From 697f317c5e4d672a71e1e0ad26668e61d8db511d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 22 Dec 2023 14:47:06 +0000 Subject: [PATCH] Hide market days if I'm going to be abroad at a conference Closes: #44 --- agenda/data.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/agenda/data.py b/agenda/data.py index a1d28c7..a9ceae3 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -9,7 +9,7 @@ from datetime import date, datetime, timedelta import dateutil.rrule import dateutil.tz import flask -import holidays # type: ignore +import holidays import isodate # type: ignore import lxml import pytz @@ -228,6 +228,20 @@ def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]: return events +def find_markets_during_stay( + accommodation_events: list[Event], markets: list[Event] +) -> list[Event]: + """Market events that happen during accommodation stays.""" + overlapping_markets = [] + for market in markets: + for e in accommodation_events: + # Check if the market date is within the accommodation dates. + if e.date <= market.date <= (e.end_date or e.date): + overlapping_markets.append(market) + break # Breaks the inner loop if overlap is found. + return overlapping_markets + + async def get_data( now: datetime, config: flask.config.Config ) -> typing.Mapping[str, str | object]: @@ -301,10 +315,13 @@ async def get_data( ): holidays += get_holidays(country, last_year, next_year) - events += combine_holidays(holidays) + accommodation_events = accommodation.get_events( + os.path.join(my_data, "accommodation.yaml") + ) + events += combine_holidays(holidays) events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml")) - events += accommodation.get_events(os.path.join(my_data, "accommodation.yaml")) + events += accommodation_events events += travel.all_events(my_data) events += conference.get_list(os.path.join(my_data, "conferences.yaml")) events += backwell_bins + bristol_bins @@ -316,6 +333,13 @@ async def get_data( events += domains.renewal_dates(my_data) + # hide markets that happen while away + markets = [e for e in events if e.name == "market"] + + overlapping_markets = find_markets_during_stay(accommodation_events, markets) + for market in overlapping_markets: + events.remove(market) + for launch in rockets: dt = None