Skip to content

Commit

Permalink
Merge pull request #29 from filips123/add-subject-change-category
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 authored Jun 11, 2021
2 parents 9db2898 + ba81aca commit 6bd8830
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 173 deletions.
2 changes: 1 addition & 1 deletion API/config.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sources:
timetable:
url: http://old.gimvic.org/urnik/data.js
url: http://projekti.gimvic.org/urnik/data.js
eclassroom:
url: https://ucilnica.gimvic.org/webservice/rest/server.php
token: YOUR-TOKEN-HERE
Expand Down
35 changes: 35 additions & 0 deletions API/gimvicurnik/updaters/eclassroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _store_substitutions(self, name, url, span):

header_substitutions = ["ODSOTNI UČITELJ/ICA", "URA", "RAZRED", "UČILNICA", "NADOMEŠČA", "PREDMET", "OPOMBA"]
header_lesson_change = ["RAZRED", "URA", "UČITELJ/ICA", "PREDMETA", "UČILNICA", "OPOMBA"]
header_subject_change = ["RAZRED", "URA", "UČITELJ", "PREDMET", "UČILNICA", "OPOMBA"]
header_classroom_change = ["RAZRED", "URA", "UČITELJ/ICA", "PREDMET", "IZ UČILNICE", "V UČILNICO", "OPOMBA"]
header_more_teachers = ["URA", "UČITELJ", "RAZRED", "UČILNICA", "OPOMBA"]
header_reservations = ["URA", "UČILNICA", "REZERVIRAL/A", "OPOMBA"]
Expand All @@ -189,6 +190,9 @@ def _store_substitutions(self, name, url, span):
elif row == header_lesson_change:
parser_type = "lesson-change"
continue
elif row == header_subject_change:
parser_type = "subject-change"
continue
elif row == header_classroom_change:
parser_type = "classroom-change"
continue
Expand Down Expand Up @@ -266,6 +270,37 @@ def _store_substitutions(self, name, url, span):
)
# fmt: on

elif parser_type == "subject-change":
time = row[1][:-1] if row[1] != "PU" else 0
subject = self._normalize_other_names(row[3].split(" → ")[1])

original_teacher = self._normalize_teacher_name(row[2])
original_classroom = self._normalize_other_names(row[4])

# Handle multiple classes
classes = row[0].replace(". ", "").split(" - ")
classes = classes[:-1] if len(classes) > 1 else classes

teacher = original_teacher
classroom = original_classroom

# fmt: off
for class_ in classes:
substitutions.append(
{
"date": date,
"day": day,
"time": time,
"subject": subject,
"original_teacher_id": get_or_create(self.session, model=Teacher, name=original_teacher)[0].id if original_teacher else None,
"original_classroom_id": get_or_create(self.session, model=Classroom, name=original_classroom)[0].id if original_classroom else None,
"class_id": get_or_create(self.session, model=Class, name=class_)[0].id,
"teacher_id": get_or_create(self.session, model=Teacher, name=teacher)[0].id if teacher else None,
"classroom_id": get_or_create(self.session, model=Classroom, name=classroom)[0].id if classroom else None,
}
)
# fmt: on

elif parser_type == "classroom-change":
time = row[1][:-1] if row[1] != "PU" else 0
subject = self._normalize_other_names(row[3])
Expand Down
Loading

0 comments on commit 6bd8830

Please sign in to comment.