aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index 4ce3a21..090142b 100644
--- a/utils.py
+++ b/utils.py
@@ -17,6 +17,7 @@
from django.utils import timezone
import datetime
+import re
def get_current_week():
return timezone.now().isocalendar()[:2]
@@ -44,3 +45,17 @@ def group_courses(courses):
grouped_courses[-1].append(course)
return grouped_courses
+
+def parse_group(name):
+ group_regex = re.compile("^(.+?)\s*\-\s*(((CM)(\w))|((TD)(\w)(\d))|((TP)(\w)(\d)(\d)))$")
+ search = group_regex.search(name)
+ if search is None:
+ return None, None, None, None
+
+ parts = search.groups(0)
+ if parts[3] == "CM":
+ return parts[0], parts[4], None, None
+ elif parts[6] == "TD":
+ return parts[0], parts[7], parts[8], None
+ elif parts[10] == "TP":
+ return parts[0], parts[11], parts[12], parts[13]