forked from nikosavola/fk-tiedotin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulletin.py
65 lines (47 loc) · 1.96 KB
/
bulletin.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from functools import partial
from jinja2 import Environment, FileSystemLoader
from markupsafe import Markup
from utils import grouper, category_sort, categories, categories_en, week, all_entries
# Define template behaviour.
env = Environment(
loader=FileSystemLoader('templates'),
trim_blocks=True,
lstrip_blocks=True,
)
def nl2br(s):
"""Change linebreaks to <br /> tags."""
return s.replace('\n', Markup('<br/>\n'))
env.filters['nl2br'] = nl2br # Add function to env's filters.
# Sort first by category to enable grouping.
entries = all_entries(isEnglish=False)
entries_en = all_entries(isEnglish=True)
entries = sorted(entries, key=partial(category_sort, cats=categories))
entries_en = sorted(entries_en, key=partial(category_sort, cats=categories_en))
# Group entries.
pairs = grouper(entries, categories)
pairs_en = grouper(entries_en, categories_en)
template = env.get_template('cells.html')
template_en = env.get_template('cells_en.html')
template_short = env.get_template('cells_short.html')
variables = {
"title": "Fyysikkokillan viikkotiedote",
"header": week+"/2023\n"+"Kilta tiedottaa\nGuild News",
"category_events": pairs,
"category_events_en": pairs_en,
"communications_officer": "Iris Kause",
"telegram_nick": "viestintavastaava",
"email": "[email protected]",
"week": week
}
tiedote = template.render(variables)
tiedote_en = template_en.render(variables)
tiedote_short = template_short.render(variables)
with open('mails/kilta-tiedottaa-viikko-'+week+'.html', 'w', encoding='utf-8') as f:
f.write(tiedote)
with open('mails/kilta-tiedottaa-viikko-'+week+'-en.html', 'w', encoding='utf-8') as f:
f.write(tiedote_en)
with open('mails/kilta-tiedottaa-viikko-'+week+'-short.html', 'w', encoding='utf-8') as f:
f.write(tiedote_short)
print("Bulletin made succesfully.")