mirror of
https://github.com/cqwu-ehall/cqwu-ehall.git
synced 2024-11-25 03:42:46 +00:00
✨ Support get score origin detail
This commit is contained in:
parent
23407d68ff
commit
e040d8cfc9
@ -14,6 +14,7 @@ class GetScoreDetail:
|
|||||||
search_type: Union[str, ScoreSearchType] = ScoreSearchType.XUEQI,
|
search_type: Union[str, ScoreSearchType] = ScoreSearchType.XUEQI,
|
||||||
xue_nian: int = None,
|
xue_nian: int = None,
|
||||||
xue_qi: int = None,
|
xue_qi: int = None,
|
||||||
|
origin: bool = False,
|
||||||
use_model: bool = False,
|
use_model: bool = False,
|
||||||
) -> Union[str, ScoreDetail]:
|
) -> Union[str, ScoreDetail]:
|
||||||
"""获取学业成绩"""
|
"""获取学业成绩"""
|
||||||
@ -44,7 +45,7 @@ class GetScoreDetail:
|
|||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
"sjxz": f"sjxz{search_type.value}",
|
"sjxz": f"sjxz{search_type.value}",
|
||||||
"ysyx": "yxcj",
|
"ysyx": "yscj" if origin else "yxcj",
|
||||||
"zx": "1",
|
"zx": "1",
|
||||||
"fx": "1",
|
"fx": "1",
|
||||||
"btnExport": "%B5%BC%B3%F6",
|
"btnExport": "%B5%BC%B3%F6",
|
||||||
@ -74,7 +75,7 @@ class GetScoreDetail:
|
|||||||
jw_html = jw_html.replace("charset=GBK", "charset=UTF-8")
|
jw_html = jw_html.replace("charset=GBK", "charset=UTF-8")
|
||||||
if not use_model:
|
if not use_model:
|
||||||
return jw_html
|
return jw_html
|
||||||
return parse_html(jw_html)
|
return parse_html(jw_html, origin)
|
||||||
|
|
||||||
|
|
||||||
def parse_info(tag: Tag) -> ScoreDetailInfo:
|
def parse_info(tag: Tag) -> ScoreDetailInfo:
|
||||||
@ -117,6 +118,26 @@ def parse_course(tag: Tag) -> List[ScoreDetailCourse]:
|
|||||||
return courses
|
return courses
|
||||||
|
|
||||||
|
|
||||||
|
def parse_course_origin(tag: Tag) -> List[ScoreDetailCourse]:
|
||||||
|
trs = tag.find_all("tr")
|
||||||
|
courses = []
|
||||||
|
for tr in trs:
|
||||||
|
tds = tr.find_all("td")
|
||||||
|
course = ScoreDetailCourse(
|
||||||
|
id=tds[0].text,
|
||||||
|
name=tds[1].text,
|
||||||
|
credit=tds[2].text,
|
||||||
|
period=tds[3].text,
|
||||||
|
type=tds[4].text,
|
||||||
|
nature=tds[5].text,
|
||||||
|
exam_method=tds[6].text,
|
||||||
|
score=tds[8].text,
|
||||||
|
remark=tds[9].text,
|
||||||
|
)
|
||||||
|
courses.append(course)
|
||||||
|
return courses
|
||||||
|
|
||||||
|
|
||||||
def parse_total(tag: Tag) -> ScoreDetailTotal:
|
def parse_total(tag: Tag) -> ScoreDetailTotal:
|
||||||
tr = tag.find_all("tr")[-1]
|
tr = tag.find_all("tr")[-1]
|
||||||
tds = tr.find_all("td")
|
tds = tr.find_all("td")
|
||||||
@ -132,12 +153,16 @@ def parse_total(tag: Tag) -> ScoreDetailTotal:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_html(html: str) -> ScoreDetail:
|
def parse_html(html: str, origin: bool) -> ScoreDetail:
|
||||||
soup = BeautifulSoup(html, "lxml")
|
soup = BeautifulSoup(html, "lxml")
|
||||||
group_div = soup.find("div", {"group": "group"})
|
group_div = soup.find("div", {"group": "group"})
|
||||||
info = parse_info(group_div)
|
info = parse_info(group_div)
|
||||||
tbody_s = soup.find_all("tbody")
|
tbody_s = soup.find_all("tbody")
|
||||||
courses = []
|
courses = []
|
||||||
|
total = None
|
||||||
|
if origin:
|
||||||
|
courses += parse_course_origin(tbody_s[0])
|
||||||
|
else:
|
||||||
for tbody in tbody_s[:-1]:
|
for tbody in tbody_s[:-1]:
|
||||||
courses += parse_course(tbody)
|
courses += parse_course(tbody)
|
||||||
total = parse_total(tbody_s[-1])
|
total = parse_total(tbody_s[-1])
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import List
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@ -71,5 +71,5 @@ class ScoreDetail(BaseModel):
|
|||||||
"""基本信息"""
|
"""基本信息"""
|
||||||
courses: List[ScoreDetailCourse]
|
courses: List[ScoreDetailCourse]
|
||||||
"""课程信息"""
|
"""课程信息"""
|
||||||
total: ScoreDetailTotal
|
total: Optional[ScoreDetailTotal] = None
|
||||||
"""总计"""
|
"""总计"""
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="cqwu", # 用自己的名替换其中的YOUR_USERNAME_
|
name="cqwu", # 用自己的名替换其中的YOUR_USERNAME_
|
||||||
version="0.0.18", # 包版本号,便于维护版本
|
version="0.0.19", # 包版本号,便于维护版本
|
||||||
author="omg-xtao", # 作者,可以写自己的姓名
|
author="omg-xtao", # 作者,可以写自己的姓名
|
||||||
author_email="xtao@xtaolink.cn", # 作者联系方式,可写自己的邮箱地址
|
author_email="xtao@xtaolink.cn", # 作者联系方式,可写自己的邮箱地址
|
||||||
description="A cqwu ehall client.", # 包的简述
|
description="A cqwu ehall client.", # 包的简述
|
||||||
|
Loading…
Reference in New Issue
Block a user