コード例 #1
0
    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")
コード例 #2
0
    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)
コード例 #3
0
ファイル: timeline.py プロジェクト: ivanhrabcak/edupage-api
    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