Compare commits

...

2 commits

Author SHA1 Message Date
Edward Betts 73d8f7eb47 Gap page to show trips
Closes: #90, #97
2024-01-23 15:58:01 +00:00
Edward Betts d6ebd86232 Add more emojis 2024-01-23 15:57:36 +00:00
4 changed files with 68 additions and 7 deletions

View file

@ -37,7 +37,7 @@ from . import (
uk_tz, uk_tz,
waste_schedule, waste_schedule,
) )
from .types import Event, StrDict from .types import Event, StrDict, Trip
here = dateutil.tz.tzlocal() here = dateutil.tz.tzlocal()
@ -144,10 +144,14 @@ def get_yaml_event_end_date_field(item: dict[str, str]) -> str:
) )
def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]: def read_events_yaml(
data_dir: str, start: date, end: date, skip_trips: bool = False
) -> list[Event]:
"""Read eventes from YAML file.""" """Read eventes from YAML file."""
events: list[Event] = [] events: list[Event] = []
for item in yaml.safe_load(open(os.path.join(data_dir, "events.yaml"))): for item in yaml.safe_load(open(os.path.join(data_dir, "events.yaml"))):
if "trip" in item and skip_trips:
continue
duration = ( duration = (
isodate.parse_duration(item["duration"]) if "duration" in item else None isodate.parse_duration(item["duration"]) if "duration" in item else None
) )
@ -247,10 +251,10 @@ def busy_event(e: Event) -> bool:
"event", "event",
"accommodation", "accommodation",
"conference", "conference",
"dodainville",
"transport", "transport",
"meetup", "meetup",
"party", "party",
"trip",
}: }:
return False return False
@ -281,6 +285,40 @@ async def time_function(
return name, result, end_time - start_time return name, result, end_time - start_time
def gap_list(
today: date, config: flask.config.Config, trips: list[Trip]
) -> list[StrDict]:
last_year = today - timedelta(days=365)
next_year = today + timedelta(days=2 * 365)
my_data = config["PERSONAL_DATA"]
events = read_events_yaml(my_data, last_year, next_year, skip_trips=True)
for trip in trips:
event_type = "trip"
if trip.events and not trip.conferences:
event_type = trip.events[0]["name"]
elif len(trip.conferences) == 1 and trip.conferences[0].get("hackathon"):
event_type = "hackathon"
events.append(
Event(
name=event_type,
title=trip.title + " " + trip.country_flags,
date=trip.start,
end_date=trip.end,
url=flask.url_for("trip_page", start=trip.start.isoformat()),
)
)
busy_events = [
e
for e in sorted(events, key=lambda e: e.as_date)
if e.as_date > today and e.as_date < next_year and busy_event(e)
]
return find_gaps(busy_events)
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]:

View file

@ -132,6 +132,8 @@ emojis = {
"economist": "📰", "economist": "📰",
"running": "🏃", "running": "🏃",
"critical_mass": "🚴", "critical_mass": "🚴",
"trip": "🧳",
"hackathon": "💻",
} }

View file

@ -17,11 +17,31 @@
<tbody> <tbody>
{% for gap in gaps %} {% for gap in gaps %}
<tr> <tr>
<td>{% for event in gap.before %}{% if not loop.first %}<br/>{% endif %}<span class="text-nowrap">{{ event.title or event.name }}</span>{% endfor %}</td> <td class="text-start">
{% for event in gap.before %}
<div class="text-nowrap">
{% if event.url %}
<a href="{{event.url}}">{{ event.title_with_emoji }}</a>
{% else %}
{{ event.title_with_emoji }}
{% endif %}
</div>
{% endfor %}
</td>
<td class="text-end text-nowrap">{{ gap.start.strftime("%A, %-d %b %Y") }}</td> <td class="text-end text-nowrap">{{ gap.start.strftime("%A, %-d %b %Y") }}</td>
<td class="text-end text-nowrap">{{ (gap.end - gap.start).days }} days</td> <td class="text-end text-nowrap">{{ (gap.end - gap.start).days }} days</td>
<td class="text-end text-nowrap">{{ gap.end.strftime("%A, %-d %b %Y") }}</td> <td class="text-end text-nowrap">{{ gap.end.strftime("%A, %-d %b %Y") }}</td>
<td>{% for event in gap.after %}{% if not loop.first %}<br/>{% endif %}<span class="text-nowrap">{{ event.title or event.name }}</span>{% endfor %}</td> <td class="text-start">
{% for event in gap.after %}
<div class="text-nowrap">
{% if event.url %}
<a href="{{event.url}}">{{ event.title_with_emoji }}</a>
{% else %}
{{ event.title_with_emoji }}
{% endif %}
</div>
{% endfor %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View file

@ -86,8 +86,9 @@ def launch_list() -> str:
async def gaps_page() -> str: async def gaps_page() -> str:
"""List of available gaps.""" """List of available gaps."""
now = datetime.now() now = datetime.now()
data = await agenda.data.get_data(now, app.config) trip_list = agenda.trip.build_trip_list()
return flask.render_template("gaps.html", today=now.date(), gaps=data["gaps"]) gaps = agenda.data.gap_list(now.date(), app.config, trip_list)
return flask.render_template("gaps.html", today=now.date(), gaps=gaps)
@app.route("/travel") @app.route("/travel")