summaryrefslogtreecommitdiff
path: root/admin/update-index.py
diff options
context:
space:
mode:
Diffstat (limited to 'admin/update-index.py')
-rwxr-xr-xadmin/update-index.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/admin/update-index.py b/admin/update-index.py
new file mode 100755
index 0000000..5946433
--- /dev/null
+++ b/admin/update-index.py
@@ -0,0 +1,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:])