def parse(person_data: dict, person_id: int, edupage: EdupageModule) -> Optional[EduAccount]: account_type = EduAccount.recognize_account_type(person_data) if account_type == EduAccountType.STUDENT: class_id = ModuleHelper.parse_int(person_data.get("classid")) name = DbiHelper(edupage).fetch_student_name(person_id) gender = Gender.parse(person_data.get("gender")) student_since = ModuleHelper.strptime_or_none( person_data.get("datefrom"), "%Y-%m-%d") number_in_class = ModuleHelper.parse_int( person_data.get("numberinclass")) ModuleHelper.assert_none(name) return EduStudent(person_id, name, gender, student_since, class_id, number_in_class) elif account_type == EduAccountType.TEACHER: classroom_id = person_data.get("classroomid") classroom_name = DbiHelper(edupage).fetch_classroom_number( classroom_id) if ModuleHelper.parse_int(classroom_id) else "" name = DbiHelper(edupage).fetch_teacher_name(person_id) gender = Gender.parse(person_data.get("gender")) if teacher_since_str := person_data.get("datefrom"): teacher_since = datetime.strptime(teacher_since_str, "%Y-%m-%d") else: teacher_since = None if teacher_to_str := person_data.get("dateto"): teacher_to = datetime.strptime(teacher_to_str, "%Y-%m-%d")
def get_timetable_changes(self, date: date) -> Optional[list[TimetableChange]]: html = self.__get_substitution_data(date) class_delim = ( "</div><div class=\"section print-nobreak\">" "<div class=\"header\"><span class=\"print-font-resizable\">") changes_by_class_dirty = html.split(class_delim)[1:] if not changes_by_class_dirty: return None footer_delim = ( "<div style=\"text-align:center;font-size:12px\">" "<a href=\"https://www.asctimetables.com\" target=\"_blank\">" "www.asctimetables.com</a> -") changes_by_class_dirty[-1] = changes_by_class_dirty[-1].split( footer_delim)[0] changes = [(x.replace("</div>", "").replace( "<div class=\"period\">", "").replace("<span class=\"print-font-resizable\">", "").replace("<div class=\"info\">", "")) for x in changes_by_class_dirty] lesson_changes = [] for class_changes in changes: class_changes_data = class_changes.split( "</span><div class=\"rows\">") change_class = class_changes_data[0] class_changes_rows = class_changes_data[1].split( "<div class=\"row ")[1:] for change in class_changes_rows: change = change.replace("\">", "</span>") action, lesson_n, title = change.split("</span>")[:-1] if "<img src=" in title: title = title.split(">")[1] action = Action.parse(action) if "-" in lesson_n: lesson_from, lesson_to = lesson_n.split(" - ") lesson_n = (ModuleHelper.parse_int(lesson_from), ModuleHelper.parse_int(lesson_to)) else: lesson_n = ModuleHelper.parse_int(lesson_n) lesson_change = TimetableChange(change_class, lesson_n, title, action) lesson_changes.append(lesson_change) return lesson_changes