Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pytyut/BuildingApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_teach_building_by_campus_id(self, xqh):
req_url = self.node + 'Tschedule/Zhcx/GetJxlhByXqh'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_free_class_info(self, zc: str = '', xq: str = '', ksjc: str = '', jsjc: str = '', xqh: str = '',
Expand All @@ -53,7 +53,7 @@ def get_free_class_info(self, zc: str = '', xq: str = '', ksjc: str = '', jsjc:
req_url = self.node + 'Tschedule/Zhcx/GetPageListJson'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_classroom_tree_by_campus(self):
Expand All @@ -64,7 +64,7 @@ def get_classroom_tree_by_campus(self):
req_url = self.node + 'Tschedule/Zhcx/GetXqJxlJasTreeJson'
res = self.session.post(req_url, data=GET_CLASSROOM_TREE_BY_CAMPUS_REQUEST_DATA, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()


Expand All @@ -83,5 +83,5 @@ def get_course_schedule_by_classroom(self, semester: str= "now", xqh: str= "01",
req_url = self.node + 'Tschedule/Zhcx/GetSjjsSjddByJash'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()
2 changes: 1 addition & 1 deletion pytyut/ClassApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def get_major_class_tree(self, semester):
req_url = self.node + 'Tschedule/Zhcx/GetNjxszyTreeByrwbjJson'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()
4 changes: 2 additions & 2 deletions pytyut/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_user_info(self):
req_url = self.node + 'Home/StudentResult'
res = self.session.get(req_url, headers=self.default_headers)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
avatar = self.session.get(self.node + 'Tresources/AXsgj/ZpResultXs', headers=self.default_headers).content
param = '<div class="profile-info-name">([^^]*?)</div>[^^]*?<[^^]*?>(.*)</[^^]*?>'
result = re.findall(param, res.text)
Expand All @@ -92,7 +92,7 @@ def get_total_grades_result(self):
# 这里请求数据与获取课程成绩用的数据是一样的
res = self.session.post(req_url, data=GET_COURSE_SCORE_REQUEST_DATA, headers=self.default_headers)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
if '评教未完成' in res.text:
raise CourseException("评教未完成,系统限制不予允许查询成绩!")
key_info_list = re.findall('<div class="profile-info-name">([^<]*?)</div>', res.text)
Expand Down
22 changes: 11 additions & 11 deletions pytyut/CourseApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_course_schedule(self) -> dict:
"""
res = self.session.post(self.node + 'Tresources/A1Xskb/GetXsKb', headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_all_course_score(self, moreInformation=False) -> list:
Expand All @@ -52,7 +52,7 @@ def get_all_course_score(self, moreInformation=False) -> list:
req_url = self.node + '/Home/GetBxqcj'
res = self.session.post(req_url, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
html_text = json.loads(res.text)["rpath"]["m_StringValue"]
# html_text = html_text.replace('<font style="color: #ff0000">', '').replace('</font>', '')
param = '''<tr><td height='20%' width='80%' style=\\"vertical-align:middle; \\">([^<]*?)</td><td height='20%' width='20%' style=\\"vertical-align:middle; \\">([^<]*?)</td> </tr>'''
Expand All @@ -63,7 +63,7 @@ def get_all_course_score(self, moreInformation=False) -> list:
res = self.session.post(req_url, headers=DEFAULT_HEADERS, data=GET_COURSE_SCORE_REQUEST_DATA)

if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()

if '评教未完成' in res.text:
raise CourseException("评教未完成,系统限制不予允许查询成绩!")
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_test_info(self, semester: str = "now", moreInformation=False) -> list:
}
res = self.session.post(req_url, headers=DEFAULT_HEADERS, data=data)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
html_text = json.loads(res.text)["rpath"]["m_StringValue"]
html_text = html_text.replace('<font style="color: #ff0000">', '').replace('</font>', '')
param = '''<tr><td height='20%' width='10%' style="vertical-align:middle; ">([^<]*?)</td><td height='20%' width='25%' style="vertical-align:middle; ">([^<]*?)</td><td height='20%' width='37%' style="vertical-align:middle; ">([^<]*?)</td> <td height='20%' width='30%' style="vertical-align:middle; ">([^<]*?)</td></tr>'''
Expand All @@ -127,7 +127,7 @@ def get_test_info(self, semester: str = "now", moreInformation=False) -> list:
data = build_get_test_info_request_data(semester)
res = self.session.post(req_url, headers=DEFAULT_HEADERS, data=data)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_course_schedule_by_bjh(self, semester: str, bjh: str) -> dict:
Expand All @@ -145,7 +145,7 @@ def get_course_schedule_by_bjh(self, semester: str, bjh: str) -> dict:
req_url = self.node + 'Tschedule/Zhcx/GetSjjsSjddByBjh'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_selectable_course_list(self, semester: str = 'now') -> dict:
Expand All @@ -165,7 +165,7 @@ def get_selectable_course_list(self, semester: str = 'now') -> dict:
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)

if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_select_course_list(self, pid: str, semester: str = 'now') -> dict:
Expand All @@ -185,7 +185,7 @@ def get_select_course_list(self, pid: str, semester: str = 'now') -> dict:
req_url = self.node + 'Tschedule/C4Xkgl/GetXkkcListByXh'
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
json_info = res.json()

# 判断有没有用错接口
Expand All @@ -206,7 +206,7 @@ def get_selected_course_list(self) -> dict:
data = build_get_selected_course_list_request_data()
res = self.session.post(req_url, data=data, headers=DEFAULT_HEADERS)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_set_cookie(self, headers: dict) -> str:
Expand Down Expand Up @@ -247,7 +247,7 @@ def select_course(self, json_info) -> dict:
data['__RequestVerificationToken'] = self.get_set_cookie(headers)
res = self.session.post(req_url, data=data, headers=headers)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

# TODO: 未经测试
Expand Down Expand Up @@ -278,7 +278,7 @@ def remove_course(self, json_info, course_Id):
data['__RequestVerificationToken'] = self.get_set_cookie(headers)
res = self.session.post(req_url, data=data, headers=headers)
if '出错' in res.text or '教学管理服务平台(S)' in res.text:
raise LoginException().login_timeout()
raise LoginException.login_timeout()
return res.json()

def get_course_schedule_by_classroom(self, xnxq, xqh, jxlh, jash):
Expand Down
8 changes: 3 additions & 5 deletions pytyut/excepiton/LoginException.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class LoginException(Exception):
def __init__(self, msg: str = "未知异常"):
self.msg = msg

def get_msg(self):
return self.msg

def login_timeout(self):
self.msg = "登录已失效"
@staticmethod
def login_timeout() -> "LoginException":
return LoginException("登录已失效")