From 85bca858a8b4082c00f055dde442748354673e16 Mon Sep 17 00:00:00 2001 From: HanseGucker <joniweth@gmx.de> Date: Fri, 22 Feb 2019 18:08:44 +0100 Subject: [PATCH] Format classes better (issue #118) --- biscuit/apps/untis/sub.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/biscuit/apps/untis/sub.py b/biscuit/apps/untis/sub.py index 723f79a..b12192d 100644 --- a/biscuit/apps/untis/sub.py +++ b/biscuit/apps/untis/sub.py @@ -207,6 +207,31 @@ def generate_room_row(sub, full=False): return room +def format_classes(classes): + """ + Formats a list of Class objects to a combined string + + example return: "9abcd" for classes 9a, 9b, 9c and 9d + + :param classes: Class list + :return: combined string + """ + classes_as_dict = {} + + for _class in classes: + step = _class.name[:-1] + part = _class.name[-1:] + if step not in classes_as_dict.keys(): + classes_as_dict[step] = [part] + else: + classes_as_dict[step].append(part) + + out = "" + for key, value in classes_as_dict.items(): + out += key + "".join(value) + return out + + def generate_sub_table(subs): sub_rows = [] for sub in subs: @@ -225,8 +250,9 @@ def generate_sub_table(subs): else: sub_row.lesson = "{}.".format(sub.lesson) - for class_ in sub.classes: - sub_row.classes += class_.name + # for class_ in sub.classes: + # sub_row.classes += class_.name + sub_row.classes = format_classes(sub.classes) sub_row.teacher = generate_teacher_row(sub) sub_row.teacher_full = generate_teacher_row(sub, full=True) -- GitLab