Пример #1
0
 def set_base_info(self):
     """设置账户基本信息, 如用户id, 姓名, 学校等"""
     r = self._session.get(Url.INFO_URL)
     json_data = r.json()["student"]
     if not json_data.get("clazz", False):
         raise UserDefunctError()
     self.code = json_data.get("code")
     self.name = json_data.get("name")
     self.avatar = json_data.get("avatar")
     self.gender = Sex.BOY if json_data.get("gender") == "1" else Sex.GIRL
     self.username = json_data.get("loginName")
     self.id = json_data.get("id")
     self.mobile = json_data.get("mobile")
     self.email = json_data.get("email")
     self.qq_number = json_data.get("im")
     self.clazz = StuClass(
         id=json_data["clazz"]["id"],
         name=json_data["clazz"]["name"],
         school=School(
             id=json_data["clazz"]["division"]["school"]["id"],
             name=json_data["clazz"]["division"]["school"]["name"]),
         grade=Grade(code=json_data["clazz"]["division"]["grade"]["code"],
                     name=json_data["clazz"]["division"]["grade"]["name"],
                     phase=Phase(code=json_data["clazz"]["division"]
                                 ["grade"]["phase"]["code"],
                                 name=json_data["clazz"]["division"]
                                 ["grade"]["phase"]["name"])))
     self.birthday = json_data.get("birthday", 0)
     return self
Пример #2
0
 def __get_classmates(self, clazz_id: str) -> ExtendedList[StuPerson]:
     classmates = StuPersonList()
     r = self._session.get(Url.GET_CLASSMATES_URL,
                           params={
                               "r": f"{self.id}student",
                               "clazzId": clazz_id
                           })
     json_data = r.json()
     for classmate_data in json_data:
         birthday = int(int(classmate_data.get("birthday", 0)) / 1000)
         classmate = StuPerson(
             name=classmate_data["name"],
             id=classmate_data["id"],
             clazz=StuClass(
                 id=classmate_data["clazz"]["id"],
                 name=classmate_data["clazz"]["name"],
                 grade=self.clazz.grade,
                 school=School(
                     id=classmate_data["clazz"]["school"]["id"],
                     name=classmate_data["clazz"]["school"]["name"])),
             code=classmate_data.get("code"),
             email=classmate_data["email"],
             qq_number=classmate_data["im"],
             gender=Sex.BOY
             if classmate_data["gender"] == "1" else Sex.GIRL,
             mobile=classmate_data["mobile"])
         classmate.birthday = birthday
         classmates.append(classmate)
     return classmates
Пример #3
0
 def set_base_info(self):
     """设置账户基本信息, 如用户id, 姓名, 学校等"""
     r = self._session.get(Url.INFO_URL)
     if not r.ok:
         raise PageConnectionError(f"set_base_info出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()["student"]
         if not json_data.get("clazz", False):
             raise UserDefunctError()
         self.code = json_data.get("code")
         self.name = json_data.get("name")
         self.avatar = json_data.get("avatar")
         self.gender = Sex.BOY if json_data.get(
             "gender") == "1" else Sex.GIRL
         self.username = json_data.get("loginName")
         self.id = json_data.get("id")
         self.mobile = json_data.get("mobile")
         self.email = json_data.get("email")
         self.qq_number = json_data.get("im")
         self.clazz = StuClass(
             id=json_data["clazz"]["id"],
             name=json_data["clazz"]["name"],
             school=School(
                 id=json_data["clazz"]["division"]["school"]["id"],
                 name=json_data["clazz"]["division"]["school"]["name"]),
             grade=Grade(
                 code=json_data["clazz"]["division"]["grade"]["code"],
                 name=json_data["clazz"]["division"]["grade"]["name"],
                 phase=Phase(code=json_data["clazz"]["division"]["grade"]
                             ["phase"]["code"],
                             name=json_data["clazz"]["division"]["grade"]
                             ["phase"]["name"])))
         self.birthday = json_data.get("birthday", 0)
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"set_base_info中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return self
Пример #4
0
 def __get_classmates(self, clazz_id: str) -> ExtendedList[StuPerson]:
     classmates = StuPersonList()
     r = self._session.get(Url.GET_CLASSMATES_URL,
                           params={
                               "r": f"{self.id}student",
                               "clazzId": clazz_id
                           })
     if not r.ok:
         raise PageConnectionError(
             f"__get_classmates中出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()
         for classmate_data in json_data:
             birthday = int(int(classmate_data.get("birthday", 0)) / 1000)
             classmate = StuPerson(
                 name=classmate_data["name"],
                 id=classmate_data["id"],
                 clazz=StuClass(
                     id=classmate_data["clazz"]["id"],
                     name=classmate_data["clazz"]["name"],
                     grade=self.clazz.grade,
                     school=School(
                         id=classmate_data["clazz"]["school"]["id"],
                         name=classmate_data["clazz"]["school"]["name"])),
                 code=classmate_data.get("code"),
                 email=classmate_data["email"],
                 qq_number=classmate_data["im"],
                 gender=Sex.BOY
                 if classmate_data["gender"] == "1" else Sex.GIRL,
                 mobile=classmate_data["mobile"])
             classmate.birthday = birthday
             classmates.append(classmate)
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"__get_classmates中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return classmates