diff --git a/agenda/data.py b/agenda/data.py index d209020..27e2cf1 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -287,10 +287,9 @@ async def time_function( return name, result, end_time - start_time, exception -def get_busy_events( +def gap_list( today: date, config: flask.config.Config, trips: list[Trip] -) -> list[Event]: - """Find busy events from a year ago to two years in the future.""" +) -> list[StrDict]: last_year = today - timedelta(days=365) next_year = today + timedelta(days=2 * 365) @@ -312,7 +311,6 @@ def get_busy_events( url=flask.url_for("trip_page", start=trip.start.isoformat()), ) ) - # pprint(events) busy_events = [ e @@ -320,41 +318,7 @@ def get_busy_events( if e.as_date > today and e.as_date < next_year and busy_event(e) ] - return busy_events - - -def weekends(busy_events: list[Event]) -> typing.Sequence[StrDict]: - """Next ten weekends.""" - today = datetime.today() - weekday = today.weekday() - - # Calculate the difference to the next or previous Saturday - if weekday == 6: # Sunday - start_date = (today - timedelta(days=1)).date() - else: - start_date = (today + timedelta(days=(5 - weekday))).date() - - weekends_info = [] - for i in range(52): - saturday = start_date + timedelta(weeks=i) - sunday = saturday + timedelta(days=1) - - saturday_events = [ - event - for event in busy_events - if event.end_date and event.as_date <= saturday <= event.end_as_date - ] - sunday_events = [ - event - for event in busy_events - if event.end_date and event.as_date <= sunday <= event.end_as_date - ] - - weekends_info.append( - {"date": saturday, "saturday": saturday_events, "sunday": sunday_events} - ) - - return weekends_info + return find_gaps(busy_events) async def get_data( diff --git a/templates/navbar.html b/templates/navbar.html index 4f4046c..2ba8830 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -7,7 +7,6 @@ {"endpoint": "travel_list", "label": "Travel" }, {"endpoint": "accommodation_list", "label": "Accommodation" }, {"endpoint": "gaps_page", "label": "Gaps" }, - {"endpoint": "weekends", "label": "Weekends" }, {"endpoint": "launch_list", "label": "Space launches" }, {"endpoint": "holiday_list", "label": "Holidays" }, ] %} diff --git a/templates/weekends.html b/templates/weekends.html deleted file mode 100644 index a5d7659..0000000 --- a/templates/weekends.html +++ /dev/null @@ -1,44 +0,0 @@ -{% extends "base.html" %} - -{% block content %} -
| Week | -Date | -Saturday | -Sunday | -
|---|---|---|---|
| - {{ weekend.date.isocalendar().week }} - | -- {{ weekend.date.strftime("%-d %b %Y") }} - | - {% for day in "saturday", "sunday" %} -- {% if weekend[day] %} - {% for event in weekend[day] %} - {{ event.title }}{% if not loop.last %},{%endif %} - {% endfor %} - {% else %} - 🆓 🍃 📖 - {% endif %} - | - {% endfor %} -