diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-03-08 21:59:45 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2021-03-08 22:01:56 +0100 |
| commit | abe13f4e73c2e15b26ef9fa3334e88ad97c5a126 (patch) | |
| tree | a887f5a5589c2f2636d65c6a90970469c14aaa18 /build-programs.py | |
| parent | f2559fee5f7caeaa773fdd8708f11e2441976039 (diff) | |
| download | quatuorbellefeuille.com-abe13f4e73c2e15b26ef9fa3334e88ad97c5a126.tar.xz | |
Move all programs into a single file
This means we do not need to keep track of their order out-of-band,
and it will allow members to edit them without me whipping up an
ad-hoc file-upload dialog on the admin page.
Diffstat (limited to 'build-programs.py')
| -rwxr-xr-x | build-programs.py | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/build-programs.py b/build-programs.py index 513abbe..69c7057 100755 --- a/build-programs.py +++ b/build-programs.py @@ -1,28 +1,22 @@ #!/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>.+)', + r'NOM : (?P<name>[^\n]+)', + r'COMPOSITEURS : (?P<composers>[^\n]+)', 'DESCRIPTION :', - '(?P<description>.+)', + '(?P<description>.+?)', 'MORCEAUX :', - '(?P<pieces>.+)' + r'(?P<pieces>(?:- [^\n]+\n)*- [^\n]+)' )), flags=re.DOTALL) -def parse(filename): - with open(filename) as program: - return PROGRAM_RE.match(program.read()).groupdict() +def read_programs(programs): + with open(programs) as f: + return tuple(re.finditer(PROGRAM_RE, f.read())) BLOCK_TEMPLATE = '''\ @@ -45,24 +39,23 @@ def piece(p): return '<li class="intermission">entracte</li>' return f'<li>{html.escape(p)}</li>' -def print_program(filename): - info = parse(filename) - +def print_program(info): 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() + piece(p[2:]) # Assume p.startswith('- '). + 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) + for p in read_programs('programs.in'): + print_program(p.groupdict()) if __name__ == '__main__': |
