From c9415599cafd67463b6a0a2781ecb47d14fdf976 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 23 Feb 2021 23:24:42 +0100 Subject: Add first program, plus script to generate them --- build-programs.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 build-programs.py (limited to 'build-programs.py') 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.+)', + 'COMPOSITEURS : (?P.+)', + 'DESCRIPTION :', + '(?P.+)', + 'MORCEAUX :', + '(?P.+)' +)), flags=re.DOTALL) + +def parse(filename): + with open(filename) as program: + return PROGRAM_RE.match(program.read()).groupdict() + + +BLOCK_TEMPLATE = '''\ +
+ +
{name}
+
{composers}
+ + +
+{description} +
    +{pieces} +
+
+''' + +def piece(p): + if p == 'entracte': + return '
  • entracte
  • ' + return f'
  • {html.escape(p)}
  • ' + +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() -- cgit v1.2.3