diff options
Diffstat (limited to 'admin')
| -rwxr-xr-x | admin/build-indexes.sh | 15 | ||||
| -rwxr-xr-x | admin/update-index.py | 51 |
2 files changed, 66 insertions, 0 deletions
diff --git a/admin/build-indexes.sh b/admin/build-indexes.sh new file mode 100755 index 0000000..9dcbda7 --- /dev/null +++ b/admin/build-indexes.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -eu + +HERE=$(dirname "$0") +ROOT=${HERE}/.. + +for directory +do + concert="${directory}"/concerts.in + index="${directory}"/index.html + + PYTHONPATH="${ROOT}" \ + "${HERE}"/update-index.py "${concert}" "${index}" +done 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:]) |
