MCPcopy Create free account
hub / github.com/EdupageAPI/edupage-api / parse

Method parse

edupage_api/people.py:47–87  ·  view source on GitHub ↗
(
        person_data: dict, person_id: int, edupage: EdupageModule
    )

Source from the content-addressed store, hash-verified

45
46 @staticmethod
47 def parse(
48 person_data: dict, person_id: int, edupage: EdupageModule
49 ) -> Optional[EduAccount]:
50 account_type = EduAccount.recognize_account_type(person_data)
51
52 if account_type == EduAccountType.STUDENT:
53 class_id = ModuleHelper.parse_int(person_data.get("classid"))
54 name = DbiHelper(edupage).fetch_student_name(person_id)
55 gender = Gender.parse(person_data.get("gender"))
56 student_since = ModuleHelper.strptime_or_none(
57 person_data.get("datefrom"), "%Y-%m-%d"
58 )
59 number_in_class = ModuleHelper.parse_int(person_data.get("numberinclass"))
60
61 ModuleHelper.assert_none(name)
62
63 return EduStudent(
64 person_id, name, gender, student_since, class_id, number_in_class
65 )
66 elif account_type == EduAccountType.TEACHER:
67 classroom_id = person_data.get("classroomid")
68 classroom_name = DbiHelper(edupage).fetch_classroom_number(classroom_id)
69
70 name = DbiHelper(edupage).fetch_teacher_name(person_id)
71
72 gender = Gender.parse(person_data.get("gender"))
73 if teacher_since_str := person_data.get("datefrom"):
74 teacher_since = datetime.strptime(teacher_since_str, "%Y-%m-%d")
75 else:
76 teacher_since = None
77
78 if teacher_to_str := person_data.get("dateto"):
79 teacher_to = datetime.strptime(teacher_to_str, "%Y-%m-%d")
80 else:
81 teacher_to = None
82
83 return EduTeacher(
84 person_id, name, gender, teacher_since, classroom_name, teacher_to
85 )
86 else:
87 return None
88
89 def get_id(self):
90 return f"{self.account_type.value}{self.person_id}"

Callers

nothing calls this directly

Calls 11

DbiHelperClass · 0.90
EduStudentClass · 0.85
EduTeacherClass · 0.85
parse_intMethod · 0.80
fetch_student_nameMethod · 0.80
strptime_or_noneMethod · 0.80
assert_noneMethod · 0.80
fetch_teacher_nameMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected