diff options
author | emkael <emkael@tlen.pl> | 2021-11-21 16:16:42 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2021-11-21 16:16:42 +0100 |
commit | fb020853caf99d085340c7efeae046eb8a9beb7c (patch) | |
tree | 427c529a9ed13ddca43a37d67b14fb31cf88009d /boards/generate.py | |
parent | 0d07462fac19b41f31701044306b9bcd475b42a9 (diff) |
Hand records WWW generator - 1+2 after 4 matches
Diffstat (limited to 'boards/generate.py')
-rw-r--r-- | boards/generate.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/boards/generate.py b/boards/generate.py new file mode 100644 index 0000000..13c7d72 --- /dev/null +++ b/boards/generate.py @@ -0,0 +1,50 @@ +import json, sys +from datetime import datetime +from pathlib import Path + + +config_dir = Path('config') +for config_path in config_dir.glob('*.json'): + config_name = config_path.stem + print('Found config "%s" in %s' % (config_name, config_path), file=sys.stderr) + with open(config_path) as config_file: + config = json.load(config_file) + + output_dir = Path('output') / config_name + output_dir.mkdir(parents=True, exist_ok=True) + + content = '' + for section in config['sections']: + content += '<tr><td class="bdnt12" colspan="3">%s</td></tr>' % (section['title']) + for dealset in section['sets']: + set_enabled = False + set_finished = True + set_content = '<tr><td class="bdcc1" colspan="3">%s</td></tr>' % (dealset['title']) + for pbn in dealset['files']: + if pbn.get('enabled', 0): + set_enabled = True + set_content += '<tr>' + set_content += '<td class="bd1">%s</td>' % (pbn['name']) + for filetype in ('pbn', 'pdf'): + set_content += '<td class="bdc"><a class="zb" href="files/%s.%s">%s</a></td>' % (pbn['path'], filetype, filetype) + set_content += '</tr>' + else: + set_finished = False + if set_finished: + set_content += '<tr>' + set_content += '<td class="bd1" colspan="2">%s</td>' % (dealset['zip'].get('title', 'cały mecz')) + set_content += '<td class="bdc"><a class="zb" href="files/%s.zip">zip</a></td>' % (dealset['zip']['id']) + set_content += '</tr>' + if set_enabled: + content += set_content + content += '<tr><td class="e" colspan="3"> </td></tr>' + + with open('template/%s.html' % (config_name)) as template_file: + template = template_file.read() + with open('template/%s.logo.html' % (config_name)) as logoh_file: + template = template.replace('<!---[LOGOH]--->', logoh_file.read()) + template = template.replace('<!---[CONTENT]--->', content) + template = template.replace('<!---[GENDATE]--->', datetime.now().strftime('%Y-%m-%d %X')) + + with open(output_dir / 'index.html', 'w') as output_file: + output_file.write(template) |