aboutsummaryrefslogtreecommitdiff
path: root/management/parsers/ups2019.py
diff options
context:
space:
mode:
Diffstat (limited to 'management/parsers/ups2019.py')
-rw-r--r--management/parsers/ups2019.py42
1 files changed, 20 insertions, 22 deletions
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