From a85f2fb91d1a4a0e31c41c392e404d7ddbf21109 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 1 Sep 2019 12:41:19 +0200 Subject: ups2019: réadaptation du parseur L’emplacement des différents éléments a changé, mdr. Signed-off-by: Alban Gruin --- management/parsers/ups2019.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'management') diff --git a/management/parsers/ups2019.py b/management/parsers/ups2019.py index c7ab7c9..c6bd7e3 100644 --- a/management/parsers/ups2019.py +++ b/management/parsers/ups2019.py @@ -27,9 +27,6 @@ from .ups2018 import GROUP_PREFIXES class Parser(AbstractParser): - def __get_name(self, raw_name): - return raw_name.split('[')[1][:-1] - def __get_event(self, event, year, week): if event["allDay"]: return @@ -56,41 +53,42 @@ class Parser(AbstractParser): celcat_id=event["id"] ) - i = 0 + max_i = len(data) + if event.get("eventCategory") is not None and \ len(event.get("eventCategory", "")) > 0: course.type = event["eventCategory"] - i = 1 + max_i -= 1 if event.get("module", "") is not None and \ len(event.get("module", "")) > 0: module, _ = Module.objects.get_or_create(name=event["module"]) course.module = module - if '[' in data[i]: - course.name = self.__get_name(data[i]) - i += 1 - - while '[' in data[i]: - course.name += ", " + self.__get_name(data[i]) - i += 1 - - while i < len(data) and not data[i].startswith(GROUP_PREFIXES): + i = 0 + while i < max_i and not data[i].startswith(GROUP_PREFIXES): rooms.append(data[i]) i += 1 course.rooms.add(*Room.objects.filter(name__in=rooms)) - while i < len(data) and data[i].startswith(GROUP_PREFIXES): - groups.append(Group.objects.get_or_create( - source=self.source, celcat_name=data[i] - )[0]) + if len(rooms) != course.rooms.count(): + print(rooms, course.rooms) + + while i < max_i and data[i].startswith(GROUP_PREFIXES): + group, _ = Group.objects.get_or_create(source=self.source, + celcat_name=data[i]) + groups.append(group) i += 1 course.groups.add(*groups) - if i < len(data): - course.notes = "\n".join(data[i:]).strip() - if "other" in course.notes: - print("Warning: 'other' in course.notes") + if i < max_i and course.module is not None and \ + data[i].startswith(course.module.name): + course.name = data[i] + i += 1 + + course.notes = "\n".join(data[i:max_i]).strip() + if "other" in data[i]: + print("Warning: \"other\" in notes") return course -- cgit v1.2.1