diff --git a/agenda/data.py b/agenda/data.py index 23dd6e1..1cb891f 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -37,7 +37,7 @@ from . import ( uk_tz, waste_schedule, ) -from .types import Event, StrDict, Trip +from .types import Event, StrDict here = dateutil.tz.tzlocal() @@ -144,14 +144,10 @@ def get_yaml_event_end_date_field(item: dict[str, str]) -> str: ) -def read_events_yaml( - data_dir: str, start: date, end: date, skip_trips: bool = False -) -> list[Event]: +def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]: """Read eventes from YAML file.""" events: list[Event] = [] for item in yaml.safe_load(open(os.path.join(data_dir, "events.yaml"))): - if "trip" in item and skip_trips: - continue duration = ( isodate.parse_duration(item["duration"]) if "duration" in item else None ) @@ -251,10 +247,10 @@ def busy_event(e: Event) -> bool: "event", "accommodation", "conference", + "dodainville", "transport", "meetup", "party", - "trip", }: return False @@ -285,40 +281,6 @@ async def time_function( 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( now: datetime, config: flask.config.Config ) -> typing.Mapping[str, str | object]: diff --git a/agenda/types.py b/agenda/types.py index c0f28b1..37f656e 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -132,8 +132,6 @@ emojis = { "economist": "📰", "running": "🏃", "critical_mass": "🚴", - "trip": "🧳", - "hackathon": "💻", } diff --git a/templates/gaps.html b/templates/gaps.html index 7cb7fbf..ae24883 100644 --- a/templates/gaps.html +++ b/templates/gaps.html @@ -17,31 +17,11 @@ {% for gap in gaps %} - - {% for event in gap.before %} -
- {% if event.url %} - {{ event.title_with_emoji }} - {% else %} - {{ event.title_with_emoji }} - {% endif %} -
- {% endfor %} - + {% for event in gap.before %}{% if not loop.first %}
{% endif %}{{ event.title or event.name }}{% endfor %} {{ gap.start.strftime("%A, %-d %b %Y") }} {{ (gap.end - gap.start).days }} days {{ gap.end.strftime("%A, %-d %b %Y") }} - - {% for event in gap.after %} -
- {% if event.url %} - {{ event.title_with_emoji }} - {% else %} - {{ event.title_with_emoji }} - {% endif %} -
- {% endfor %} - + {% for event in gap.after %}{% if not loop.first %}
{% endif %}{{ event.title or event.name }}{% endfor %} {% endfor %} diff --git a/web_view.py b/web_view.py index 9d72286..16aa6d7 100755 --- a/web_view.py +++ b/web_view.py @@ -86,9 +86,8 @@ def launch_list() -> str: async def gaps_page() -> str: """List of available gaps.""" now = datetime.now() - trip_list = agenda.trip.build_trip_list() - gaps = agenda.data.gap_list(now.date(), app.config, trip_list) - return flask.render_template("gaps.html", today=now.date(), gaps=gaps) + data = await agenda.data.get_data(now, app.config) + return flask.render_template("gaps.html", today=now.date(), gaps=data["gaps"]) @app.route("/travel")