From 9ce185579dd4c7b1a53117bf7f73778bb84d28c7 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 30 Aug 2023 15:24:09 +0200 Subject: support filling the class, start and end dates --- scripts/gen_map/gen_map.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'scripts/gen_map') diff --git a/scripts/gen_map/gen_map.py b/scripts/gen_map/gen_map.py index c3866ee0..979045b6 100755 --- a/scripts/gen_map/gen_map.py +++ b/scripts/gen_map/gen_map.py @@ -277,12 +277,23 @@ def gen_latex_table( return rows -def print_map(rows: list[str], template_path: Path, outfile): +def print_map(rows: list[str], template_path: Path, outfile, + map_info: dict[t.Union[str, datetime]]): """Print the template including the generated table""" with open(template_path, 'r', encoding='utf-8') as template_file: template = template_file.readlines() template_prefix = template[:-8] + for i, line in enumerate(template_prefix): + if r'Start' in line: + template_prefix[ + i] = f'\\Start{{{map_info["start"].strftime("%d.%m.%y")}}}\n' + elif 'End' in line: + template_prefix[ + i] = f'\\End{{{map_info["end"].strftime("%d.%m.%y")}}}\n' + elif 'Klasse' in line: + template_prefix[i] = f'\\Klasse{{{map_info["form"]}?}}\n' + template_suffix = template[-2:] print(''.join(template_prefix), file=outfile, end='') @@ -324,11 +335,16 @@ def main(): else: template_path = TEMPLATE_DIR / TEMPLATE_FILE + map_info = { + 'form': args.form, + 'start': school_holidays[0].end, + 'end': school_holidays[-1].start + } if args.output != sys.stdout: with open(args.output, 'w', encoding='utf-8') as outfile: - print_map(rows, template_path, outfile) + print_map(rows, template_path, outfile, map_info) else: - print_map(rows, template_path, args.output) + print_map(rows, template_path, args.output, map_info) if __name__ == '__main__': -- cgit v1.2.3