blob: 594643310d8ca848fd7a093a2986e70d2ba844f2 (
plain)
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
|
#!/usr/bin/env python3
from datetime import datetime
from sys import argv
from helpers import (
guess_language,
read_concerts,
split_concerts,
tmplocale,
)
CALENDAR_LAYOUT = {
'en': '<span id="month">%B</span><br><span id="day">%d</span>',
'fr': '<span id="day">%d</span><br><span id="month">%B</span>',
}
INDEX_TEMPLATE = '''\
<main>
<a id="next-concert" href="concerts.html#concert-%F">
<p>
{CALENDAR}
</p>
</a>
</main>
'''
def main(concerts_src, index_dst):
today = datetime.fromordinal(
datetime.today().date().toordinal()
)
past_concerts, next_concerts = split_concerts(
read_concerts(concerts_src), today
)
concert = next_concerts[0] if next_concerts else past_concerts[-1]
lang = guess_language(concerts_src)
template = INDEX_TEMPLATE.format(CALENDAR=CALENDAR_LAYOUT[lang])
with tmplocale(lang):
index = concert.time.strftime(template)
with open(index_dst, 'w') as index_file:
index_file.write(index)
if __name__ == '__main__':
main(*argv[1:])
|