From 7134160ada7a3e08d4c463bcc410043125a203c5 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 16 Nov 2025 19:41:58 +0100 Subject: improve spgen script and add new template --- spgen.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'spgen.py') diff --git a/spgen.py b/spgen.py index 30b5956..42ddfed 100755 --- a/spgen.py +++ b/spgen.py @@ -11,14 +11,19 @@ class SPTemplate(Template): delimiter = '%%' -def print_sp_template(template: SPTemplate, duration: str, names: list[str]): - defs = [rf'\csdef{{name{i+1}}}{{{n}}}' for i, n in enumerate(names)] +def print_sp_template(template: SPTemplate, duration: str, names: list[str], + seats: list[int]): + """Print the template including our name definitions""" + defs = [] + for name in names: + seat = seats.pop() + defs.append(rf'\csdef{{name{seat}}}{{{name}}}') defs.append(rf'\csdef{{duration}}{{{duration}}}') print(template.substitute({'defs': '\n'.join(defs)})) def main(): - """Entry point generating a random seating plan from students names""" + """Entry point generating a random seating plan from student names""" parser = argparse.ArgumentParser() parser.add_argument('template') @@ -27,10 +32,12 @@ def main(): '--duration', default=f'KW: {datetime.datetime.now().isocalendar()[1]}') duration_group.add_argument('--week', type=int) + duration_group.add_argument('--seats', type=int) args = parser.parse_args() names = [line[:-1] for line in sys.stdin.readlines()] - random.shuffle(names) + seats = list(range(1, (args.seats if args.seats else len(names)) + 1)) + random.shuffle(seats) duration = args.duration if args.week: @@ -51,7 +58,7 @@ def main(): with open(args.template, 'r', encoding='utf-8') as template_file: template = SPTemplate(template_file.read()) - print_sp_template(template, duration, names) + print_sp_template(template, duration, names, seats) if __name__ == '__main__': -- cgit v1.2.3