-
Notifications
You must be signed in to change notification settings - Fork 6
/
pyconfr.py
115 lines (83 loc) · 3.07 KB
/
pyconfr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import json
from pathlib import Path
from babel.dates import format_date, format_time, format_timedelta
from datetime import date, time, timedelta
from flask import Flask, Response, render_template, url_for
from flask_frozen import Freezer
from flask_weasyprint import render_pdf
from markdown2 import Markdown
from sassutils.wsgi import SassMiddleware
from slugify import slugify
app = Flask(__name__, static_url_path='/2024/static')
app.wsgi_app = SassMiddleware(app.wsgi_app, {
'pyconfr': {
'sass_path': 'static/sass',
'css_path': 'static/css',
'wsgi_path': '/2024/static/css',
'strip_extension': True}})
with (Path(app.root_path) / 'schedule.json').open() as fd:
SCHEDULE = json.load(fd)
_GIT_MAIN = Path(app.root_path) / '.git' / 'refs' / 'heads' / 'main'
GIT_VERSION = _GIT_MAIN.read_text().strip()[:7]
@app.template_filter()
def slug(string):
return slugify(string, max_length=30)
TALK_CATEGORIES = {
slug(talk['submission_type']['en']): talk['submission_type']
for dates in
tuple(SCHEDULE['schedule'].values()) + tuple(SCHEDULE['sprints'].values())
for hours in dates.values()
for talk in hours.values()
}
@app.template_filter()
def format_duration(minutes):
return format_timedelta(
timedelta(seconds=minutes*60), threshold=10, format='short')
@app.template_filter()
def format_day(day, lang):
day_date = date.fromisoformat(day)
return format_date(day_date, format='full', locale=lang)
@app.template_filter()
def format_minutes(minutes, lang):
hour_time = time(int(minutes) // 60, int(minutes) % 60)
return format_time(hour_time, format='short', locale=lang)
@app.template_filter()
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.template_filter()
def version(url):
return f'{url}?{GIT_VERSION}'
@app.route('/')
@app.route('/2024/')
@app.route('/2024/<lang>/<name>.html')
def page(name='index', lang='fr'):
return render_template(
f'{lang}/{name}.jinja2.html', page_name=name, lang=lang,
schedule=SCHEDULE)
@app.route('/2024/<lang>/talks/<category>.html')
def talks(lang, category):
return render_template(
f'{lang}/talks.jinja2.html', lang=lang, page_name='talks',
category=category, title=TALK_CATEGORIES[category][lang],
schedule=SCHEDULE, categories=TALK_CATEGORIES)
@app.route('/2024/<lang>/full-schedule.html')
def schedule(lang):
return render_template(
'schedule.jinja2.html', page_name='full-schedule', lang=lang,
schedule=SCHEDULE)
@app.route('/2024/<lang>/full-schedule.pdf')
def pdf_schedule(lang):
return render_pdf(url_for('schedule', lang=lang))
@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')
def freeze():
Freezer(app).freeze()