Module edupage_api.people
Classes
class EduAccount (person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], account_type: EduAccountType)
-
EduAccount(person_id: 'int', name: 'str', gender: 'Gender', in_school_since: 'Optional[datetime]', account_type: 'EduAccountType')
Expand source code
@dataclass class EduAccount: person_id: int name: str gender: Gender in_school_since: Optional[datetime] account_type: EduAccountType @staticmethod def recognize_account_type(person_data: dict) -> EduAccountType: if person_data.get("numberinclass") is not None: return EduAccountType.STUDENT elif person_data.get("classroomid") is not None: return EduAccountType.TEACHER else: return EduAccountType.PARENT @staticmethod 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) 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") else: teacher_to = None return EduTeacher( person_id, name, gender, teacher_since, classroom_name, teacher_to ) else: return None def get_id(self): return f"{self.account_type.value}{self.person_id}"
Subclasses
Class variables
var account_type : EduAccountType
var gender : Gender
var in_school_since : Optional[datetime.datetime]
var name : str
var person_id : int
Static methods
def parse(person_data: dict, person_id: int, edupage: EdupageModule) ‑> Optional[EduAccount]
def recognize_account_type(person_data: dict) ‑> EduAccountType
Methods
def get_id(self)
class EduAccountType (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class EduAccountType(str, Enum): STUDENT = "Student" TEACHER = "Teacher" PARENT = "Rodic"
Ancestors
- builtins.str
- enum.Enum
Class variables
var PARENT
var STUDENT
var TEACHER
class EduParent (person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime])
-
EduParent(person_id: 'int', name: 'str', gender: 'Gender', in_school_since: 'Optional[datetime]')
Expand source code
@dataclass class EduParent(EduAccount): def __init__( self, person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], ): super().__init__( person_id, name, gender, in_school_since, EduAccountType.PARENT )
Ancestors
Class variables
var account_type : EduAccountType
var gender : Gender
var in_school_since : Optional[datetime.datetime]
var name : str
var person_id : int
class EduStudent (person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], class_id: int, number_in_class: int)
-
EduStudent(person_id: 'int', name: 'str', gender: 'Gender', in_school_since: 'Optional[datetime]', class_id: 'int', number_in_class: 'int')
Expand source code
@dataclass class EduStudent(EduAccount): def __init__( self, person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], class_id: int, number_in_class: int, ): super().__init__( person_id, name, gender, in_school_since, EduAccountType.STUDENT ) self.class_id = class_id self.number_in_class = number_in_class self.__student_only = False def get_id(self): if not self.__student_only: return super().get_id() else: return super().get_id().replace("Student", "StudentOnly") def set_student_only(self, student_only: bool): self.__student_only = student_only
Ancestors
Class variables
var account_type : EduAccountType
var gender : Gender
var in_school_since : Optional[datetime.datetime]
var name : str
var person_id : int
Methods
def get_id(self)
def set_student_only(self, student_only: bool)
class EduStudentSkeleton (person_id: int, name_short: str, class_id: int)
-
EduStudentSkeleton(person_id: 'int', name_short: 'str', class_id: 'int')
Expand source code
@dataclass class EduStudentSkeleton: person_id: int name_short: str class_id: int
Class variables
var class_id : int
var name_short : str
var person_id : int
class EduTeacher (person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], classroom_name: str, teacher_to: Optional[datetime])
-
EduTeacher(person_id: 'int', name: 'str', gender: 'Gender', in_school_since: 'Optional[datetime]', classroom_name: 'str', teacher_to: 'Optional[datetime]')
Expand source code
@dataclass class EduTeacher(EduAccount): def __init__( self, person_id: int, name: str, gender: Gender, in_school_since: Optional[datetime], classroom_name: str, teacher_to: Optional[datetime], ): super().__init__( person_id, name, gender, in_school_since, EduAccountType.TEACHER ) self.teacher_to = teacher_to self.classroom_name = classroom_name
Ancestors
Class variables
var account_type : EduAccountType
var gender : Gender
var in_school_since : Optional[datetime.datetime]
var name : str
var person_id : int
class Gender (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class Gender(str, Enum): MALE = "M" FEMALE = "F" @staticmethod def parse(gender_str: str) -> Optional[Gender]: return ModuleHelper.parse_enum(gender_str, Gender)
Ancestors
- builtins.str
- enum.Enum
Class variables
var FEMALE
var MALE
Static methods
def parse(gender_str: str) ‑> Optional[Gender]
class People (edupage: EdupageModule)
-
Expand source code
class People(Module): @ModuleHelper.logged_in def get_students(self) -> Optional[list]: students = DbiHelper(self.edupage).fetch_student_list() if students is None: return None result = [] for student_id_str in students: if not student_id_str: continue student_id = int(student_id_str) student_data = students.get(student_id_str) student = EduAccount.parse(student_data, student_id, self.edupage) result.append(student) return result @ModuleHelper.logged_in def get_all_students(self) -> Optional[list[EduStudent]]: request_url = f"https://{self.edupage.subdomain}.edupage.org/rpr/server/maindbi.js?__func=mainDBIAccessor" data = { "__args": [ None, self.edupage.get_school_year(), {}, { "op": "fetch", "needed_part": { "students": ["id", "classid", "short"], }, }, ], "__gsh": self.edupage.gsec_hash, } response = self.edupage.session.post(request_url, json=data).content.decode() students = json.loads(response).get("r").get("tables")[0].get("data_rows") result = [] for student in students: student_id = int(student["id"]) student_class_id = int(student["classid"]) if student["classid"] else None student_name_short = student["short"] student = EduStudentSkeleton( student_id, student_name_short, student_class_id ) result.append(student) return result @ModuleHelper.logged_in def get_teacher(self, teacher_id: Union[int, str]) -> Optional[EduTeacher]: try: teacher_id = int(teacher_id) except (ValueError, TypeError): return None return next( ( teacher for teacher in self.get_teachers() if teacher.person_id == teacher_id ), None, ) @ModuleHelper.logged_in def get_student(self, student_id: Union[int, str]) -> Optional[EduStudent]: try: student_id = int(student_id) except (ValueError, TypeError): return None return next( ( student for student in self.get_students() if student.person_id == student_id ), None, ) @ModuleHelper.logged_in def get_teachers(self) -> Optional[list]: teachers = DbiHelper(self.edupage).fetch_teacher_list() if teachers is None: return None result = [] for teacher_id_str in teachers: if not teacher_id_str: continue teacher_id = int(teacher_id_str) teacher_data = teachers.get(teacher_id_str) teacher = EduAccount.parse(teacher_data, teacher_id, self.edupage) result.append(teacher) return result
Ancestors
Methods
def get_all_students(self) ‑> Optional[list[EduStudent]]
def get_student(self, student_id: Union[int, str]) ‑> Optional[EduStudent]
def get_students(self) ‑> Optional[list]
def get_teacher(self, teacher_id: Union[int, str]) ‑> Optional[EduTeacher]
def get_teachers(self) ‑> Optional[list]