Skip to content

Commit

Permalink
Merge pull request #79 from filips123/store-timetable-entities
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 authored Aug 29, 2023
2 parents f15b95d + 1b72e35 commit b327321
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions API/gimvicurnik/updaters/timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,22 @@ def _parse(self, document: Document | None, raw_data: str, new_hash: str, span:
]
# fmt: on

# Store timetable lessons
self.session.query(Lesson).delete()
self.session.execute(insert(Lesson), models)

# Store a list of all classes from timetable
for class_ in re.findall(r"razredi\[\d+] = \"([^\"\n]*)\"", raw_data, re.MULTILINE):
get_or_create(self.session, model=Class, name=class_)

# Store a list of all teachers from timetable
for teacher in re.findall(r"ucitelji\[\d+] = \"([^\"\n]*)\"", raw_data, re.MULTILINE):
get_or_create(self.session, model=Teacher, name=teacher)

# Store a list of all classrooms from timetable
for classroom in re.findall(r"ucilnice\[\d+] = \"([^\"\n]*)\"", raw_data, re.MULTILINE):
get_or_create(self.session, model=Classroom, name=classroom)

# Update or create a document
if not document:
document = Document()
Expand Down

0 comments on commit b327321

Please sign in to comment.