Hide market days if I'm going to be abroad at a conference

Closes: #44
This commit is contained in:
Edward Betts 2023-12-22 14:47:06 +00:00
parent aa612b94f0
commit 697f317c5e

View file

@ -9,7 +9,7 @@ from datetime import date, datetime, timedelta
import dateutil.rrule import dateutil.rrule
import dateutil.tz import dateutil.tz
import flask import flask
import holidays # type: ignore import holidays
import isodate # type: ignore import isodate # type: ignore
import lxml import lxml
import pytz import pytz
@ -228,6 +228,20 @@ def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
return events 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( async def get_data(
now: datetime, config: flask.config.Config now: datetime, config: flask.config.Config
) -> typing.Mapping[str, str | object]: ) -> typing.Mapping[str, str | object]:
@ -301,10 +315,13 @@ async def get_data(
): ):
holidays += get_holidays(country, last_year, next_year) 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 += 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 += travel.all_events(my_data)
events += conference.get_list(os.path.join(my_data, "conferences.yaml")) events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
events += backwell_bins + bristol_bins events += backwell_bins + bristol_bins
@ -316,6 +333,13 @@ async def get_data(
events += domains.renewal_dates(my_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: for launch in rockets:
dt = None dt = None