Skip to content

Commit

Permalink
Add iCal
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Sep 15, 2024
1 parent 24df311 commit f033f7d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.venv:
python3 -m venv .venv
.venv/bin/pip install setuptools frozen-flask flask libsass markdown2 icalendar python-slugify babel
.venv/bin/pip install setuptools frozen-flask flask libsass markdown2 python-slugify babel

install: .venv

Expand Down
19 changes: 14 additions & 5 deletions pyconfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from datetime import date, time, timedelta
from flask import Flask, Response, render_template
from flask_frozen import Freezer
from icalendar import Calendar
from markdown2 import Markdown
from sassutils.wsgi import SassMiddleware
from slugify import slugify
Expand Down Expand Up @@ -58,6 +57,16 @@ def markdown(string):
return Markdown().convert(string)


@app.template_filter()
def ical_datetime(string):
return string.replace('-', '').replace(':', '').split('+')[0]


@app.template_filter()
def ical_text(string):
return string.replace('\n', '\n\t')


@app.route('/')
@app.route('/2024/')
@app.route('/2024/<lang>/<name>.html')
Expand All @@ -82,10 +91,10 @@ def schedule(lang):
schedule=SCHEDULE)


@app.route('/2024/pyconfr-2024.ics')
def calendar():
calendar = Calendar.from_ical('TODO')
return Response(calendar.to_ical(), mimetype='text/calendar')
@app.route('/2024/<lang>/calendar.ics')
def calendar(lang):
ics = render_template('calendar.jinja2.ics', lang=lang, schedule=SCHEDULE)
return Response(ics, mimetype='text/calendar')


@app.cli.command('freeze')
Expand Down
19 changes: 19 additions & 0 deletions templates/calendar.jinja2.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN:VCALENDAR
VERSION:2.0
NAME:PyConFR 2024
PRODID:-//PyConFR//NONSGML PyConFR//{{ lang | upper }}
{%- for day, hours in schedule.schedule.items() -%}
{%- for minutes, talks in hours.items() -%}
{%- for talk in talks.values() %}
BEGIN:VEVENT
UID:{{ talk.code }}
DTSTART:{{ talk.slot.start | ical_datetime }}
DTEND:{{ talk.slot.end | ical_datetime }}
SUMMARY:{{ talk.title | ical_text }} ({{ talk.speakers | map(attribute="name") | join(", ") }})
DESCRIPTION:{{ talk.description | ical_text }}
LOCATION:{{ talk.slot.room[lang] }}
END:VEVENT
{%- endfor -%}
{%- endfor -%}
{%- endfor %}
END:VCALENDAR
2 changes: 1 addition & 1 deletion templates/en/schedule.jinja2.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h3>Calendar</h3>
<p>
The calendar is available below, in a
<a href="{{ url_for('schedule', lang=lang) }}">fullscreen page</a>, or
<a href="{{ url_for('calendar') }}">in your favourite calendar application</a>.
<a href="{{ url_for('calendar', lang=lang) }}">in your favourite calendar application</a>.
</p>
<p>
You can read the description of
Expand Down
2 changes: 1 addition & 1 deletion templates/fr/schedule.jinja2.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h3>Calendrier</h3>
<p>
Le calendrier est disponible ci-dessous, sur une
<a href="{{ url_for('schedule', lang=lang) }}">page en plein écran</a>,
ou <a href="{{ url_for('calendar') }}">dans votre application de calendrier favorite</a>.
ou <a href="{{ url_for('calendar', lang=lang) }}">dans votre application de calendrier favorite</a>.
</p>
<p>
Vous pouvez également lire la description des
Expand Down

0 comments on commit f033f7d

Please sign in to comment.