Compare commits

..

No commits in common. "f3f9ee5bf93586ddf2c58d3e1ad4512481c555da" and "38dccc15299a607939d59f9aa173b0748f14b82e" have entirely different histories.

4 changed files with 4 additions and 96 deletions

View file

@ -287,10 +287,9 @@ async def time_function(
return name, result, end_time - start_time, exception return name, result, end_time - start_time, exception
def get_busy_events( def gap_list(
today: date, config: flask.config.Config, trips: list[Trip] today: date, config: flask.config.Config, trips: list[Trip]
) -> list[Event]: ) -> list[StrDict]:
"""Find busy events from a year ago to two years in the future."""
last_year = today - timedelta(days=365) last_year = today - timedelta(days=365)
next_year = today + timedelta(days=2 * 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()), url=flask.url_for("trip_page", start=trip.start.isoformat()),
) )
) )
# pprint(events)
busy_events = [ busy_events = [
e e
@ -320,41 +318,7 @@ def get_busy_events(
if e.as_date > today and e.as_date < next_year and busy_event(e) if e.as_date > today and e.as_date < next_year and busy_event(e)
] ]
return busy_events return find_gaps(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
async def get_data( async def get_data(

View file

@ -7,7 +7,6 @@
{"endpoint": "travel_list", "label": "Travel" }, {"endpoint": "travel_list", "label": "Travel" },
{"endpoint": "accommodation_list", "label": "Accommodation" }, {"endpoint": "accommodation_list", "label": "Accommodation" },
{"endpoint": "gaps_page", "label": "Gaps" }, {"endpoint": "gaps_page", "label": "Gaps" },
{"endpoint": "weekends", "label": "Weekends" },
{"endpoint": "launch_list", "label": "Space launches" }, {"endpoint": "launch_list", "label": "Space launches" },
{"endpoint": "holiday_list", "label": "Holidays" }, {"endpoint": "holiday_list", "label": "Holidays" },
] %} ] %}

View file

@ -1,44 +0,0 @@
{% extends "base.html" %}
{% block content %}
<div class="p-2">
<h1>Weekends</h1>
<table class="table table-hover w-auto">
<thead>
<tr>
<th class="text-end">Week</th>
<th class="text-end">Date</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
</thead>
<tbody>
{% for weekend in items %}
<tr>
<td class="text-end">
{{ weekend.date.isocalendar().week }}
</td>
<td class="text-end">
{{ weekend.date.strftime("%-d %b %Y") }}
</td>
{% for day in "saturday", "sunday" %}
<td>
{% if weekend[day] %}
{% for event in weekend[day] %}
<a href="{{ event.url }}">{{ event.title }}</a>{% if not loop.last %},{%endif %}
{% endfor %}
{% else %}
<em>🆓 🍃 📖</em>
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

View file

@ -87,21 +87,10 @@ async def gaps_page() -> str:
"""List of available gaps.""" """List of available gaps."""
now = datetime.now() now = datetime.now()
trip_list = agenda.trip.build_trip_list() trip_list = agenda.trip.build_trip_list()
busy_events = agenda.data.get_busy_events(now.date(), app.config, trip_list) gaps = agenda.data.gap_list(now.date(), app.config, trip_list)
gaps = agenda.data.find_gaps(busy_events)
return flask.render_template("gaps.html", today=now.date(), gaps=gaps) return flask.render_template("gaps.html", today=now.date(), gaps=gaps)
@app.route("/weekends")
async def weekends() -> str:
"""List of available gaps."""
now = datetime.now()
trip_list = agenda.trip.build_trip_list()
busy_events = agenda.data.get_busy_events(now.date(), app.config, trip_list)
weekends = agenda.data.weekends(busy_events)
return flask.render_template("weekends.html", today=now.date(), items=weekends)
@app.route("/travel") @app.route("/travel")
def travel_list() -> str: def travel_list() -> str:
"""Page showing a list of upcoming travel.""" """Page showing a list of upcoming travel."""