-
Notifications
You must be signed in to change notification settings - Fork 5
/
pycon.py
executable file
·457 lines (373 loc) · 16.3 KB
/
pycon.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
import os
from datetime import date
from operator import itemgetter
from flask import Flask, g, request, render_template, abort, make_response, url_for, redirect
from flask_babel import Babel, gettext, lazy_gettext
from schedule import (FRIDAY1, FRIDAY2, FRIDAY3, SATURDAY1, SATURDAY2, SATURDAY3, SATURDAY4, SATURDAY5,
SUNDAY1, SUNDAY3, SUNDAY4)
from utils import get_news, get_speakers, get_talks, get_edu_speakers, get_edu_talks, encode_name, decode_name, get_jobs
EVENT = gettext('PyCon SK 2022 | Bratislava, Slovakia')
DOMAIN = 'https://2022.pycon.sk'
API_DOMAIN = 'https://api.pycon.sk'
LANGS = ('en', 'sk')
TIME_FORMAT = '%Y-%m-%dT%H:%M:%S+00:00'
app = Flask(__name__, static_url_path='/static') # pylint: disable=invalid-name
app.config['BABEL_DEFAULT_LOCALE'] = 'sk'
app.jinja_options = {'extensions': ['jinja2.ext.with_', 'jinja2.ext.i18n']}
babel = Babel(app) # pylint: disable=invalid-name
CATEGORIES = {
'tickets': lazy_gettext('Tickets'),
'conference': lazy_gettext('Conference'),
'media': lazy_gettext('Media'),
'speakers': lazy_gettext('Speakers'),
}
SPEAKERS = get_speakers()
TALKS = get_talks()
EDU_SPEAKERS = get_edu_speakers()
EDU_TALKS = get_edu_talks()
@app.route('/sitemap.xml')
def sitemap():
excluded = {'static', 'sitemap'}
pages = []
for lang in LANGS:
for rule in app.url_map.iter_rules():
if 'GET' in rule.methods and rule.endpoint not in excluded:
# `url_for` appends unknown arguments as query parameters.
# We want to avoid that when a page isn't localized.
values = {'lang_code': lang} if 'lang_code' in rule.arguments else {}
if 'name' in rule.arguments:
for speaker in SPEAKERS:
values['name'] = encode_name(speaker['name'])
pages.append(DOMAIN + url_for(rule.endpoint, **values))
elif 'category' in rule.arguments:
for category in CATEGORIES.keys():
values['category'] = category
pages.append(DOMAIN + url_for(rule.endpoint, **values))
else:
pages.append(DOMAIN + url_for(rule.endpoint, **values))
sitemap_xml = render_template('sitemap.xml', pages=pages, today=date.today())
response = make_response(sitemap_xml)
response.headers['Content-Type'] = 'application/xml'
return response
@app.route('/')
def root():
return redirect('sk/index.html')
@app.route('/<lang_code>/index.html')
def index():
template_vars = _get_template_variables(li_index='active', news=get_news(get_locale(), items=3),
categories=CATEGORIES, background_filename='img/about/header1.jpg',
speakers=SPEAKERS+EDU_SPEAKERS)
return render_template('index.html', **template_vars)
@app.route('/chat.html')
def chat():
template_vars = _get_template_variables(li_index='active', news=get_news(get_locale(), items=3),
categories=CATEGORIES, background_filename='img/about/header1.jpg',
speakers=SPEAKERS+EDU_SPEAKERS, redirect="https://discord.gg/pr2cE4uT")
return render_template('index.html', **template_vars)
@app.route('/<lang_code>/news.html')
def news():
template_vars = _get_template_variables(li_news='active', news=get_news(get_locale()), categories=CATEGORIES,
background='bkg-news')
return render_template('news.html', **template_vars)
@app.route('/<lang_code>/news/<category>.html')
def news_category(category):
if category not in CATEGORIES.keys():
abort(404)
template_vars = _get_template_variables(li_news='active', categories=CATEGORIES, background='bkg-news')
news = []
for item in get_news(get_locale()):
if category in item['categories']:
news.append(item)
template_vars['news'] = news
template_vars['category'] = category
return render_template('news.html', **template_vars)
@app.route('/<lang_code>/coc.html')
def coc():
return render_template('coc.html', **_get_template_variables(li_coc='active', background='bkg-chillout'))
@app.route('/<lang_code>/faq.html')
def faq():
return render_template('faq.html', **_get_template_variables(li_faq='active', background='bkg-chillout'))
@app.route('/<lang_code>/venue.html')
def venue():
return render_template('venue.html', **_get_template_variables(li_venue='active', background='bkg-chillout'))
@app.route('/<lang_code>/aboutus.html')
def aboutus():
return render_template('aboutus.html', **_get_template_variables(li_aboutus='active', background='bkg-index'))
@app.route('/<lang_code>/tickets.html')
def tickets():
return render_template('tickets.html', **_get_template_variables(li_tickets='active', background='bkg-index'))
@app.route('/<lang_code>/cfp.html')
def cfp():
return render_template('cfp.html', **_get_template_variables(li_cfp='active', background='bkg-speaker'))
@app.route('/<lang_code>/cfp_form.html')
def cfp_form():
return render_template('cfp_form.html', **_get_template_variables(li_cfp='active', background='bkg-workshop'))
@app.route('/<lang_code>/recording.html')
def recording():
return render_template('recording.html', **_get_template_variables(li_recording='active', background='bkg-snake'))
@app.route('/<lang_code>/cfv.html')
def cfv():
return render_template('cfv.html', **_get_template_variables(li_cfv='active', background='bkg-cfv'))
@app.route('/<lang_code>/sponsors.html')
def sponsors():
return render_template('sponsors.html', **_get_sponsors_variables(li_sponsors='active', background='bkg-index'))
@app.route('/<lang_code>/edusummit.html')
def edusummit():
#
# FRIDAY = [
# {
# 'time': '9:25 - 9:30',
# 'speakers': ['Eva Klimeková'],
# 'talk': 'Otvorenie 4. ročníka EduSummit na PyCon SK',
# },
# {
# 'time': '9:30 - 9:45',
# 'talk': 'Učíme s hardvérom'
# },
# {
# 'time': '9:45 - 10:15',
# 'talk': 'Finále súťaže SPy Cup'
# },
# {
# 'time': '10:20 - 10:50',
# 'talk': 'Vzbuďme v študentoch chuť programovať!'
# },
# {
# 'time': '11:05 - 12:05',
# 'talk': 'Ako sa dá s Python zvládnuť štvorročné štúdium na strednej škole',
# 'keynote': 'True'
# },
# {
# 'time': '13:10 - 13:35',
# 'talk': 'EDUTalks'
# },
# {
# 'time': '13:35- 13:55',
# 'speakers': ['Peter Palát'],
# 'talk': 'Internetová bezpečnosť: základy sebaobrany'
# },
# {
# 'time': '14:00- 14:30',
# 'talk': "Programujeme v Pythone hardvér",
# },
# {
# 'time': '14:45- 15:30',
# 'talk': "Python ako nástroj pre STE(A)M problémy a úlohy",
# },
# {
# 'time': '15:35- 16:05',
# 'talk': "Programovací jazyk Robot Karel po novom a online.",
# },
# {
# 'time': '16:20- 16:50',
# 'talk': 'Vyhlásenie výsledkov SPy Cup a Python Cup'
# },
# {
# 'time': '16:55- 17:25',
# 'talk': "Z maturity v pascale na pythonovskú novú maturitu, študenstká mobilná apka o pythone v pythone a jednoduché grafické rozhranie pomocou libreoffice calc",
# }
# ]
#
# FRIDAY2 = [
# {
# 'time': '11:05- 12:10',
# 'talk': "Programovanie vlastných micro:bit herných ovládačov a autíčok",
# },
# {
# 'time': '13:10 - 13:55',
# 'talk': "Životopis predáva",
# },
# {
# 'time': '14:00 - 16:00',
# 'talk': "Buď SMART s micro:bitom",
# }
# ]
#
# SATURDAY = [
# {
# 'time': '9:00 - 10:50',
# 'talk': "Robíme IoT na mikrokontroléri ESP32 v jazyku MicroPython"
# },
# {
# 'time': '11:05 - 12:10',
# 'talk': "Jednoduchý blog vo Flasku",
# },
# {
# 'time': '13:10 - 15:00',
# 'talk': "Buď SMART s micro:bitom",
# },
# {
# 'time': '15:20 - 16:50',
# 'speakers': ['Jaroslav Výbošťok', 'Marek Mansell'],
# 'talk': "Využitie otvorených dát a GPS s použitím tkinter a Jupyter"
# }
# ]
#
# SATURDAY2 = [
# {
# 'time': '9:00 - 10:50',
# 'talk': "Zábava a informatika idú ruka v ruke ! :)",
# },
# {
# 'time': '11:05 - 12:10',
# 'talk': "Naučte sa programovať s CoderDojo",
# },
# {
# 'time': '13:10 - 14:10',
# 'talk': "Naprogramuj si robota Ozobot EVO",
# },
# ]
for spot in FRIDAY2:
for talk in EDU_TALKS:
if spot['title'] == talk['title']:
spot['talk'] = talk
spot['speakers'] = talk['speakers']
continue
for spot in SATURDAY2:
for talk in EDU_TALKS:
if spot['title'] == talk['title']:
spot['talk'] = talk
spot['speakers'] = talk['speakers']
continue
return render_template('edusummit.html', **_get_template_variables(li_edusummit='active', background='bkg-index',
friday2=FRIDAY2, saturday2=SATURDAY2,
speakers=EDU_SPEAKERS, talks=EDU_TALKS))
@app.route('/<lang_code>/thanks.html')
def thanks():
return render_template('thanks.html', **_get_template_variables(li_cfp='active', background='bkg-index'))
@app.route('/<lang_code>/privacy-policy.html')
def privacy_policy():
return render_template('privacy-policy.html', **_get_template_variables(li_privacy='active',
background='bkg-privacy'))
@app.route('/<lang_code>/program/index.html')
def program():
# variables = _get_template_variables(li_program='active', background='bkg-speaker', speakers=SPEAKERS)
# variables['talks_list'] = []
# variables['workshops_link'] = []
#
# for talk in TALKS:
# if talk['type'] == 'Talk':
# variables['talks_list'].append({
# 'talk': talk,
# 'speakers': talk['speakers']
# })
# continue
# elif talk['type'] == 'Workshop':
# variables['workshops_link'].append({
# 'talk': talk,
# 'speakers': talk['speakers']
# })
# continue
#
# return render_template('program.html', **variables)
return redirect('/')
@app.route('/<lang_code>/speakers/index.html')
def speakers():
variables = _get_template_variables(li_speakers='active', background='bkg-speaker', speakers=SPEAKERS+EDU_SPEAKERS)
return render_template('speaker_list.html', **variables)
@app.route('/<lang_code>/speakers/<name>.html')
def profile(name):
variables = _get_template_variables(li_speakers='active', background='bkg-speaker')
for speaker in SPEAKERS+EDU_SPEAKERS:
speaker['talks'] = []
if speaker['name'].lower() == decode_name(name):
for talk in TALKS + EDU_TALKS:
if speaker['name'] in talk.get('speakers', []):
speaker.get('talks', []).append(talk)
variables['speaker'] = speaker
break
if not variables.get('speaker'):
return abort(404)
return render_template('speaker.html', **variables)
@app.route('/<lang_code>/friday.html')
def friday():
return render_template('schedule.html', **_get_template_variables(li_friday='active', magna=FRIDAY1,
minor=FRIDAY2, babbageovaA=FRIDAY3,
day=gettext('Friday'),
background='bkg-speaker'
))
@app.route('/<lang_code>/saturday.html')
def saturday():
return render_template('schedule.html', **_get_template_variables(li_saturday='active', magna=SATURDAY1,
minor=SATURDAY2, babbageovaA=SATURDAY3,
babbageovaB=SATURDAY4, digilab=SATURDAY5,
day=gettext('Saturday'),
background='bkg-speaker'))
@app.route('/<lang_code>/sunday.html')
def sunday():
return render_template('schedule.html', **_get_template_variables(li_sunday='active', magna=SUNDAY1,
babbageovaA=SUNDAY3, babbageovaB=SUNDAY4,
day=gettext('Sunday'),
background='bkg-speaker'))
@app.route('/<lang_code>/countdown.html')
def countdown():
template_vars = _get_template_variables(li_index='active', background='bkg-index')
return render_template('countdown.html', **template_vars)
@app.route('/<lang_code>/jobs.html')
def jobs():
job_offers = get_jobs()
companies = sorted(set(map(itemgetter("company"), job_offers)))
template_vars = _get_template_variables(
li_jobs='active',
background='bkg-chillout',
jobs=job_offers,
companies=companies
)
return render_template('jobs.html', **template_vars)
@app.route('/<lang_code>/livestream-titans-room.html')
def livestream_titans_room():
template_vars = _get_template_variables(
li_livestream1='active',
background='bkg-speaker',
room_name='Titans room',
youtube_stream='1d83b19GIdM',
slido_link='https://app.sli.do/event/cEPd2DTRrEKybtAK6nget8/live/questions?section=a550b24c-5361-4dfd-af63-01f811f53da5',
)
return render_template('livestream.html', **template_vars)
def get_speaker_url():
pass
def _get_template_variables(**kwargs):
"""Collect variables for template that repeats, e.g. are in body.html template"""
variables = {
'title': EVENT,
'domain': DOMAIN,
'lang_code': get_locale(),
}
variables.update(kwargs)
return variables
def _get_schedule_variables(**kwargs):
variables = _get_template_variables(**kwargs)
lang_code = get_locale()
_schedule_vars = ['magna', 'minor', 'babbageovaA', 'babbageovaB', 'digilab']
for key, spots in kwargs.items():
if key not in _schedule_vars:
continue
for spot in spots:
name = spot.get('name')
if name is None:
continue
_speakers = [spkr.strip() for spkr in name.split(',')]
spkr = _speakers and _speakers[0] # todo fix multiple speakers
spot['speaker'] = url_for('profile', lang_code=lang_code,
name=spkr.lower().replace('-', '--').replace(' ', '-'))
# spot['speakers'] = [url_for('profile', lang_code=lang_code,
# name=spkr.lower().replace('-', '--').replace(' ', '-'))
# for spkr in _speakers]
return variables
def _get_sponsors_variables(**kwargs):
variables = _get_template_variables(**kwargs)
# todo add sponsors json and make sponsors.html jinja template
return variables
@app.before_request
def before(): # pylint: disable=inconsistent-return-statements
if request.view_args and 'lang_code' in request.view_args:
g.current_lang = request.view_args['lang_code']
if request.view_args['lang_code'] not in LANGS:
return abort(404)
request.view_args.pop('lang_code')
@babel.localeselector
def get_locale():
# try to guess the language from the user accept
# header the browser transmits. The best match wins.
# return request.accept_languages.best_match(['de', 'sk', 'en'])
return g.get('current_lang', app.config['BABEL_DEFAULT_LOCALE'])