diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-02-26 17:30:29 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-02-26 17:30:29 +0100 |
| commit | ff93d12f6e5bce471a0daf7c0a575fdeb39c3070 (patch) | |
| tree | 101c6adddaa8c778e90682f05b26456cf31116bd /build-programs.py | |
| parent | 9eef07b4d64d46947d56ad6e2a83af0414e2845b (diff) | |
| parent | fd5969367b4bd662bd9ff6710783a3d87f5bd06a (diff) | |
| download | quatuorbellefeuille.com-ff93d12f6e5bce471a0daf7c0a575fdeb39c3070.tar.xz | |
Merge branch 'programmes'
Diffstat (limited to 'build-programs.py')
| -rwxr-xr-x | build-programs.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/build-programs.py b/build-programs.py new file mode 100755 index 0000000..513abbe --- /dev/null +++ b/build-programs.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import html +from pathlib import Path +import re +from subprocess import run + + +def read_programs(plist): + with open(plist) as l: + return tuple(Path('programs', p.strip()) for p in l) + + +PROGRAM_RE = re.compile('\n'.join(( + 'NOM : (?P<name>.+)', + 'COMPOSITEURS : (?P<composers>.+)', + 'DESCRIPTION :', + '(?P<description>.+)', + 'MORCEAUX :', + '(?P<pieces>.+)' +)), flags=re.DOTALL) + +def parse(filename): + with open(filename) as program: + return PROGRAM_RE.match(program.read()).groupdict() + + +BLOCK_TEMPLATE = '''\ +<details class="program"> + <summary> + <div class="name">{name}</div> + <div class="composers">{composers}</div> + <img class="button open" src="images/chevron-down.svg"> + <img class="button close" src="images/chevron-up.svg"> + </summary> +{description} +<ol class="pieces"> +{pieces} +</ol> +</details> +''' + +def piece(p): + if p == 'entracte': + return '<li class="intermission">entracte</li>' + return f'<li>{html.escape(p)}</li>' + +def print_program(filename): + info = parse(filename) + + info['description'] = run( + ('pandoc',), + input=info['description'], capture_output=True, text=True, check=True + ).stdout + + info['pieces'] = '\n'.join( + piece(p) for p in info['pieces'].splitlines() + ) + + print(BLOCK_TEMPLATE.format_map(info)) + + +def main(): + for p in read_programs('programs/programs.list'): + print_program(p) + + +if __name__ == '__main__': + main() |
