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
def send_message(self, recipients: Union[list[EduAccount], EduAccount], body: str): recipient_string = "" if isinstance(recipients, list): for i, recipient in enumerate(recipients): recipient_string += f"{recipient.get_id()}" if i == len(recipients) - 1: recipient_string += ";" else: recipient_string = recipients.get_id() data = { "receipt": "0", "selectedUser": recipient_string, "text": body, "typ": "sprava", "attachments": "{}" } params = (("akcia", "createItem"), ) request_url = f"https://{self.edupage.subdomain}.edupage.org/timeline" self.edupage.session.post(request_url, params=params, data=ModuleHelper.encode_form_data(data))
def fetch_person_data_by_name(self, name: str) -> Optional[dict]: teacher_data = self.fetch_teacher_data_by_name(name) student_data = self.fetch_student_data_by_name(name) parent_data = self.fetch_parent_data_by_name(name) return ModuleHelper.return_first_not_null(teacher_data, student_data, parent_data)
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(self, date: datetime) -> Optional[Timetable]: dp = self.__get_dp() dates = dp.get("dates") date_plans = dates.get(date.strftime("%Y-%m-%d")) if date_plans is None: raise MissingDataException() plan = date_plans.get("plan") lessons = [] for subject in plan: header = subject.get("header") if len(header) == 0: continue subject_id = int(subject.get("subjectid")) if subject_id: subject_name = DbiHelper( self.edupage).fetch_subject_name(subject_id) else: subject_name = header[0].get("text") teachers = [] teacher_ids = subject.get("teacherids") if teacher_ids is not None and len(teacher_ids) != 0: for teacher_id_str in teacher_ids: if not teacher_id_str: continue teacher_id = int(teacher_id_str) teacher = People(self.edupage).get_teacher(teacher_id) teachers.append(teacher) classrooms = [] classroom_ids = subject.get("classroomids") if classroom_ids is not None and len(classroom_ids) != 0: for classroom_id_str in classroom_ids: if not classroom_id_str: continue classroom_id = int(classroom_id_str) classroom_number = DbiHelper( self.edupage).fetch_classroom_number(classroom_id) classrooms.append(classroom_number) start_of_lesson_str = subject.get("starttime") end_of_lesson_str = subject.get("endtime") ModuleHelper.assert_none(start_of_lesson_str, end_of_lesson_str) start_of_lesson = datetime.strptime(start_of_lesson_str, "%H:%M") end_of_lesson = datetime.strptime(end_of_lesson_str, "%H:%M") online_lesson_link = subject.get("ol_url") lesson = Lesson(teachers, classrooms, start_of_lesson, end_of_lesson, online_lesson_link, subject_id, subject_name) lessons.append(lesson) return Timetable(lessons)
def parse(string: str) -> Optional[Action]: return ModuleHelper.parse_enum(string, Action)
def get_notifications(self): output = [] timeline_items = self.edupage.data.get("items") for event in timeline_items: event_id_str = event.get("timelineid") if not event_id_str: continue event_id = int(event_id_str) event_data = json.loads(event.get("data")) event_type_str = event.get("typ") if not event_id_str: continue event_type = EventType.parse(event_type_str) if event_type is None: print(event_type_str) event_timestamp = datetime.strptime(event.get("timestamp"), "%Y-%m-%d %H:%M:%S") text = event.get("text") # what about different languages? # for message event type if text.startswith("Dôležitá správa"): text = event_data.get("messageContent") if text == "": try: text = event_data.get("nazov") except: text = "" # todo: add support for "*" recipient_name = event.get("user_meno") recipient_data = DbiHelper( self.edupage).fetch_person_data_by_name(recipient_name) if recipient_name in ["*", "Celá škola"]: recipient = "*" elif type(recipient_name) == str: recipient = recipient_name else: ModuleHelper.assert_none(recipient_data) recipient = EduAccount.parse(recipient_data, recipient_data.get("id"), self.edupage) # todo: add support for "*" author_name = event.get("vlastnik_meno") author_data = DbiHelper( self.edupage).fetch_person_data_by_name(author_name) if author_name == "*": author = "*" elif type(author_name) == str: author = author_name else: ModuleHelper.assert_none(author_data) author = EduAccount.parse(author_data, author_data.get("id"), self.edupage) additional_data = event.get("data") if additional_data and type(additional_data) == str: additional_data = json.loads(additional_data) event = TimelineEvent(event_id, event_timestamp, text, author, recipient, event_type, additional_data) output.append(event) return output
def parse(event_type_str: str) -> Optional[EventType]: return ModuleHelper.parse_enum(event_type_str, EventType)
def parse(gender_str: str) -> Optional[Gender]: return ModuleHelper.parse_enum(gender_str, Gender)