From 8efb5b6772282e11e212edf67c8befe22ea8c06f Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sat, 9 Jul 2022 15:18:29 +0200 Subject: Add plumbing to update next concert on the frontpage --- admin/update-index.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 admin/update-index.py (limited to 'admin/update-index.py') 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': '%B
%d', + 'fr': '%d
%B', +} + +INDEX_TEMPLATE = '''\ +
+ +

+ {CALENDAR} +

+
+
+''' + + +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:]) -- cgit v1.2.3