diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-02-23 23:24:42 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-02-23 23:24:42 +0100 |
| commit | c9415599cafd67463b6a0a2781ecb47d14fdf976 (patch) | |
| tree | 635682ffe96526e89a1dd02bb42ba92080f92926 /build-programs.py | |
| parent | b71cacbe6db38833176ec64c54596e928547a6b8 (diff) | |
| download | quatuorbellefeuille.com-c9415599cafd67463b6a0a2781ecb47d14fdf976.tar.xz | |
Add first program, plus script to generate them
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() |
