Skip to content

Commit

Permalink
Support negative IDs in timetables
Browse files Browse the repository at this point in the history
  • Loading branch information
BelKed committed Jul 16, 2024
1 parent a033391 commit 98bce68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
28 changes: 11 additions & 17 deletions edupage_api/foreign_timetables.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,27 @@ def get_foreign_timetable(
duration = skeleton.get("durationperiods", 1)

subject_id = skeleton.get("subjectid")
subject = (
Subjects(self.edupage).get_subject(int(subject_id))
if subject_id.isdigit()
else None
)
subject = Subjects(self.edupage).get_subject(subject_id)

class_ids = skeleton.get("classids", [])
classes = [
Classes(self.edupage).get_class(int(class_id))
for class_id in class_ids
if class_id.isdigit()
edu_class
for class_id in skeleton.get("classids", [])
if (edu_class := Classes(self.edupage).get_class(class_id)) is not None
]

groups = [group for group in skeleton.get("groupnames") if group != ""]

teacher_ids = skeleton.get("teacherids", [])
teachers = [
People(self.edupage).get_teacher(int(teacher_id))
for teacher_id in teacher_ids
if teacher_id.isdigit()
teacher
for teacher_id in skeleton.get("teacherids", [])
if (teacher := People(self.edupage).get_teacher(teacher_id)) is not None
]

classroom_ids = skeleton.get("classroomids", [])
classrooms = [
Classrooms(self.edupage).get_classroom(int(classroom_id))
for classroom_id in classroom_ids
if classroom_id.isdigit()
classroom
for classroom_id in skeleton.get("classroomids", [])
if (classroom := Classrooms(self.edupage).get_classroom(classroom_id))
is not None
]

is_removed = skeleton.get("removed") or skeleton.get("type") == "absent"
Expand Down
28 changes: 11 additions & 17 deletions edupage_api/timetables.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,27 @@ def get_timetable(self, date: date) -> Optional[Timetable]:
end_time = time(end_time_dt.hour, end_time_dt.minute)

subject_id = lesson.get("subjectid")
subject = (
Subjects(self.edupage).get_subject(int(subject_id))
if subject_id.isdigit()
else None
)
subject = Subjects(self.edupage).get_subject(subject_id)

class_ids = lesson.get("classids", [])
classes = [
Classes(self.edupage).get_class(int(class_id))
for class_id in class_ids
if class_id.isdigit()
edu_class
for class_id in lesson.get("classids", [])
if (edu_class := Classes(self.edupage).get_class(class_id)) is not None
]

groups = [group for group in lesson.get("groupnames") if group != ""]

teacher_ids = lesson.get("teacherids", [])
teachers = [
People(self.edupage).get_teacher(int(teacher_id))
for teacher_id in teacher_ids
if teacher_id.isdigit()
teacher
for teacher_id in lesson.get("teacherids", [])
if (teacher := People(self.edupage).get_teacher(teacher_id)) is not None
]

classroom_ids = lesson.get("classroomids", [])
classrooms = [
Classrooms(self.edupage).get_classroom(int(classroom_id))
for classroom_id in classroom_ids
if classroom_id.isdigit()
classroom
for classroom_id in lesson.get("classroomids", [])
if (classroom := Classrooms(self.edupage).get_classroom(classroom_id))
is not None
]

online_lesson_link = lesson.get("ol_url")
Expand Down

0 comments on commit 98bce68

Please sign in to comment.