diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2022-07-09 15:18:29 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2022-07-09 15:18:29 +0200 |
| commit | 8efb5b6772282e11e212edf67c8befe22ea8c06f (patch) | |
| tree | 2a29179a85698973fe2724ce9fc601ca96a4f944 /admin | |
| parent | 1dd8b8f4e036d2ef10a2504df1a281966f454b04 (diff) | |
| download | quatuorbellefeuille.com-8efb5b6772282e11e212edf67c8befe22ea8c06f.tar.xz | |
Add plumbing to update next concert on the frontpage
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:]) |
