From b98b23457b2b4f356447e16683bc1f0ad381757e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 09:27:44 +0200 Subject: [PATCH] add file to parse counters of tex auxiliary file --- scripts/parse_counters.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/parse_counters.py diff --git a/scripts/parse_counters.py b/scripts/parse_counters.py new file mode 100755 index 0000000..f7e20ab --- /dev/null +++ b/scripts/parse_counters.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +import re +from pathlib import Path +from typing import Dict + + +def parse_counters(filepath: Path, break_point: Dict) -> Dict: + if not filepath.is_file(): + return {} + counters: Dict = {} + with open(filepath) as f: + for line in f: + counter, _, num = re.search(r"(.*): (\d*\.)*?(\d*)", line).groups() + num = int(num) + if counter in break_point and num >= break_point[counter]: + return counters + counters[counter] = num + return counters + + +def dict2setcounters(counters: Dict): + counters_as_list = [(counter, counters[counter]) for counter in counters.keys()] + return ''.join(' ' * 4 + r'\setcounter{' + counter + '}{' + str(num) + '}\n' for (counter, num) in counters_as_list) + + +# print(dict2setcounters(parse_counters(Path('~/Uni/semester-5/topologie-1/notes/master.counters').expanduser(), +# {'exercise': 5})))