示例#1
0
    def get_latest_exam(self) -> ExamInfo:
        """获取最新考试"""
        r = self._session.get(Url.GET_RECENT_EXAM_URL,
                              headers=self.__get_auth_header())
        if not r.ok:
            raise PageConnectionError(
                f"get_latest_exam中出错, 状态码为{r.status_code}")
        try:
            json_data = r.json()["result"]
            exam_info_data = json_data["examInfo"]

            subjects = ExtendedList()

            for subject_data in exam_info_data["subjectScores"]:
                subjects.append(
                    Subject(id=subject_data["topicSetId"],
                            name=subject_data["subjectName"],
                            code=subject_data["subjectCode"]))

            exam_info = ExamInfo(id=exam_info_data["examId"],
                                 name=exam_info_data["examName"],
                                 subjects=subjects,
                                 classId=exam_info_data["classId"],
                                 grade_code=json_data["gradeCode"],
                                 is_final=exam_info_data["isFinal"])
            exam_info.create_time = exam_info_data["examCreateDateTime"]
        except (JSONDecodeError, KeyError) as e:
            raise PageInformationError(
                f"get_latest_exam中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
        return exam_info
示例#2
0
 def __get_page_exam(self, page_index: int) -> ExtendedList[Exam]:
     """获取指定页数的考试列表"""
     exams = ExtendedList()
     r = self._session.get(
         f"{Url.GET_EXAM_URL}?pageIndex={page_index}&pageSize=10&",
         headers={
             "XToken":
             self.__get_auth_header()["XToken"],
             "Referer":
             "https://www.zhixue.com/activitystudy/web-report/index.html?from=web-container_top"
         })
     json_data = r.json()
     for exam_data in json_data["result"]["examList"]:
         exam = Exam(
             id=exam_data["examId"],
             name=exam_data["examName"]  # ,
             # grade_code=exam_data["gradeCode"],
             # subject_codes=exam_data["subjectCodes"],
             # classRank=exam_data["customClassRank"],
             # gradeRank=exam_data["customSchoolRank"]
         )
         exam.create_time = exam_data["examCreateDateTime"]
         # exam.exam_time = exam_data["examDateTime"] if exam_data["examDateTime"] else 0
         exams.append(exam)
     return exams
示例#3
0
 def get_exams(self) -> ExtendedList[Exam]:
     """获取所有考试"""
     exams = ExtendedList()
     i = 1
     check = True
     while check:
         cur_exams, check = self.__get_page_exam(i)
         exams.extend(cur_exams)
         i += 1
     return exams
示例#4
0
 def get_clazzs(self) -> ExtendedList[StuClass]:
     """获取当前年级所有班级"""
     clazzs = ExtendedList()
     r = self._session.get(Url.GET_CLAZZS_URL,
                           params={"d": int(time.time())})
     json_data = r.json()
     for clazz in json_data["clazzs"]:
         clazzs.append(
             StuClass(name=clazz["name"],
                      id=clazz["id"],
                      grade=self.clazz.grade,
                      school=self.clazz.school))
     return clazzs
示例#5
0
 def __get_original(self, subject_id: str,
                    exam_id: str) -> ExtendedList[str]:
     r = self._session.get(Url.GET_ORIGINAL_URL,
                           params={
                               "examId": exam_id,
                               "paperId": subject_id,
                           },
                           headers=self.__get_auth_header())
     json_data = r.json()
     if json_data["errorCode"] != 0:
         raise Exception(json_data["errorInfo"])
     image_urls = ExtendedList()
     for image_url in json.loads(json_data["result"]["sheetImages"]):
         image_urls.append(image_url)
     return image_urls
示例#6
0
 def __get_subjects(self, exam: Exam) -> ExtendedList[Subject]:
     subjects = ExtendedList()
     r = self._session.get(Url.GET_SUBJECT_URL,
                           params={"examId": exam.id},
                           headers=self.__get_auth_header())
     json_data = r.json()
     if json_data["errorCode"] != 0:
         raise Exception(json_data["errorInfo"])
     for subject in json_data["result"]["paperList"]:
         subjects.append(
             Subject(id=subject["paperId"],
                     name=subject["subjectName"],
                     code=subject["subjectCode"],
                     standard_score=subject["standardScore"],
                     exam=exam))
     return subjects
示例#7
0
 def get_clazzs(self) -> ExtendedList[StuClass]:
     """获取当前年级所有班级"""
     clazzs = ExtendedList()
     r = self._session.get(Url.GET_CLAZZS_URL,
                           params={"d": int(time.time())})
     if not r.ok:
         raise PageConnectionError(f"get_clazzs中出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()
         for clazz in json_data["clazzs"]:
             clazzs.append(
                 StuClass(name=clazz["name"],
                          id=clazz["id"],
                          grade=self.clazz.grade,
                          school=self.clazz.school))
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"get_clazzs中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return clazzs
示例#8
0
 def __get_class_score(self, classId: str,
                       subjectId: str) -> List[SubjectScore]:
     r = self._session.get(Url.GET_REPORT_URL,
                           params={
                               "type": "export_single_paper_zip",
                               "classId": classId,
                               "studentNum": "",
                               "topicSetId": subjectId,
                               "topicNumber": "0",
                               "startScore": "0",
                               "endScore": "10000",
                           })
     data = r.json()
     subjectScores = ExtendedList()
     for pair in data["result"]:
         subjectScores.append(
             SubjectScore(score=pair["userScore"],
                          person=Person(name=pair["userName"]),
                          subject=Subject(id=subjectId)))
     return subjectScores
示例#9
0
 def __get_original(self, subject_id: str,
                    exam_id: str) -> ExtendedList[str]:
     r = self._session.get(Url.GET_ORIGINAL_URL,
                           params={
                               "examId": exam_id,
                               "paperId": subject_id,
                           },
                           headers=self.__get_auth_header())
     if not r.ok:
         raise PageConnectionError(
             f"__get_original中出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()
         image_urls = ExtendedList()
         for image_url in json.loads(json_data["result"]["sheetImages"]):
             image_urls.append(image_url)
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"__get_original中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return image_urls
示例#10
0
 def __get_page_exam(self, page_index: int) -> ExtendedList[Exam]:
     """获取指定页数的考试列表"""
     exams = ExtendedList()
     r = self._session.get(Url.GET_EXAM_URL,
                           params={
                               "actualPosition": "0",
                               "pageIndex": page_index,
                               "pageSize": 10
                           })
     json_data = r.json()
     for exam in json_data["examList"]:
         exams.append(
             Exam(id=exam["examId"],
                  name=exam["examName"],
                  create_time=int(exam["examCreateDateTime"]) / 1000,
                  exam_time=int(
                      exam["examDateTime"] if exam["examDateTime"] else 0) /
                  1000,
                  grade_code=exam["gradeCode"],
                  subject_codes=exam["subjectCodes"]))
     return exams
示例#11
0
 def __get_subjects(self, exam: Exam) -> ExtendedList[Subject]:
     subjects = ExtendedList()
     r = self._session.get(Url.GET_SUBJECT_URL,
                           params={"examId": exam.id},
                           headers=self.__get_auth_header())
     if not r.ok:
         raise PageConnectionError(
             f"__get_subjects中出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()
         for subject in json_data["result"]["paperList"]:
             subjects.append(
                 Subject(id=subject["paperId"],
                         name=subject["subjectName"],
                         code=subject["subjectCode"],
                         standard_score=subject["standardScore"],
                         exam=exam))
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"__get_subjects中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return subjects
示例#12
0
 def __get_page_exam(self, page_index: int) -> ExtendedList[Exam]:
     """获取指定页数的考试列表"""
     exams = ExtendedList()
     r = self._session.get(Url.GET_EXAM_URL,
                           params={
                               "actualPosition": "0",
                               "pageIndex": page_index,
                               "pageSize": 10
                           })
     json_data = r.json()
     for exam_data in json_data["examList"]:
         exam = Exam(id=exam_data["examId"],
                     name=exam_data["examName"],
                     grade_code=exam_data["gradeCode"],
                     subject_codes=exam_data["subjectCodes"],
                     classRank=exam_data.get("customClassRank"),
                     gradeRank=exam_data.get("customSchoolRank"))
         exam.create_time = exam_data["examCreateDateTime"]
         exam.exam_time = exam_data["examDateTime"] if exam_data[
             "examDateTime"] else 0
         exams.append(exam)
     return exams
示例#13
0
    def get_subjects(self,
                     exam_data: Union[Exam,
                                      str] = None) -> ExtendedList[Subject]:
        """获得指定考试的所有学科(不算总分)

        Args:
            exam_data (Union[Exam, str]): 考试id 或 考试名称 或 Exam实例, 默认值为最新考试

        Returns:
            ExtendedList[Subject]
        """
        exam = self.get_exam(exam_data)
        if exam is None:
            return ExtendedList([])
        return self.__get_subjects(exam)
示例#14
0
    def get_classmates(
            self,
            clazz_data: Union[StuClass,
                              str] = None) -> ExtendedList[StuPerson]:
        """获取指定班级里学生列表

        Args:
            clazz_data (Union[StuClass, str]): 班级id 或 班级名称 或 StuClass实例, 为空时获取本班学生列表

        Returns:
            ExtendedList[StuPerson]
        """
        clazz = self.get_clazz(clazz_data)
        if clazz is None:
            return ExtendedList([])
        return self.__get_classmates(clazz.id)
示例#15
0
 def __get_page_exam(self,
                     page_index: int) -> Tuple[ExtendedList[Exam], bool]:
     """获取指定页数的考试列表"""
     exams: ExtendedList[Exam] = ExtendedList()
     r = self._session.get(Url.GET_EXAM_URL,
                           params={
                               "pageIndex": page_index,
                               "pageSize": 10
                           },
                           headers=self.__get_auth_header())
     if not r.ok:
         raise PageConnectionError(
             f"__get_page_exam中出错, 状态码为{r.status_code}")
     try:
         json_data = r.json()["result"]
         for exam_data in json_data["examList"]:
             exam = Exam(id=exam_data["examId"], name=exam_data["examName"])
             exam.create_time = exam_data["examCreateDateTime"]
             exams.append(exam)
         hasNextPage: bool = json_data["hasNextPage"]
     except (JSONDecodeError, KeyError) as e:
         raise PageInformationError(
             f"__get_page_exam中网页内容发生改变, 错误为{e}, 内容为\n{r.text}")
     return exams, hasNextPage