diff --git a/edupage_api/foreign_timetables.py b/edupage_api/foreign_timetables.py index 49d4876..4932472 100644 --- a/edupage_api/foreign_timetables.py +++ b/edupage_api/foreign_timetables.py @@ -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" diff --git a/edupage_api/timetables.py b/edupage_api/timetables.py index 53e270b..7517b75 100644 --- a/edupage_api/timetables.py +++ b/edupage_api/timetables.py @@ -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")