Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix connection bug and formatfeature description text for better readability in the IDE #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions pytyut/BuildingApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, connect: Connection):
def get_teach_building_by_campus_id(self, xqh):
"""
通过校区号获取该校区的教学楼号

:param xqh: str 校区号 01 迎西校区 02 虎峪校区 06实验 08 明向校区 09 校外 10 线上
:return:
"""
Expand All @@ -41,6 +42,7 @@ def get_free_class_info(self, zc: str = '', xq: str = '', ksjc: str = '', jsjc:
jxlh: str = ''):
"""
获取空闲教室的Json信息

:param zc: str 周次 "1"
:param xq: str 星期 “1”
:param ksjc: str 开始节次 “1”
Expand All @@ -59,6 +61,7 @@ def get_free_class_info(self, zc: str = '', xq: str = '', ksjc: str = '', jsjc:
def get_classroom_tree_by_campus(self):
"""
获取历届校区教室树的Json信息

:return: list 返回历届校区教室树的json信息
"""
req_url = self.node + 'Tschedule/Zhcx/GetXqJxlJasTreeJson'
Expand All @@ -71,6 +74,7 @@ def get_classroom_tree_by_campus(self):
def get_course_schedule_by_classroom(self, semester: str= "now", xqh: str= "01", jxlh: str="101", jash: str="1009"):
"""
通过教室信息获取教室课表

:param semester: str 学年学期
:param xqh: srt 校区号 01 迎西校区 02 虎峪校区 06实验 08 明向校区 09 校外 10 线上
:param jxlh: str 教学楼号
Expand Down
1 change: 1 addition & 0 deletions pytyut/ClassApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, connection: Connection):
def get_major_class_tree(self, semester):
"""
获取历届学院专业班级树的Json信息

:param semester: 学年学期
:return: list 返回历届学院专业班级树的json信息
"""
Expand Down
7 changes: 4 additions & 3 deletions pytyut/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def __init__(self):
pass

def login(self, username: str, password: str) -> dict:
if test_node(self.node):
# 默认节点失效,重新选择节点
self.node = auto_node_choose()

self.node = auto_node_choose() # 自动判断并选择节点

self.username = username
self.__password = password
Expand Down Expand Up @@ -65,6 +64,7 @@ def get_semester(self) -> str:
def get_user_info(self):
"""
获取登录接口的Json信息

:return: dict 返回自己的json信息,头像采用二进制字节串存储。
"""
req_url = self.node + 'Home/StudentResult'
Expand All @@ -86,6 +86,7 @@ def get_user_info(self):
def get_total_grades_result(self):
"""
获取GPA、排名、总成绩等的Json信息

:return: list 返回获取GPA、排名、总成绩等的Json信息的json信息
"""
req_url = self.node + 'Tschedule/C6Cjgl/GetXskccjResult'
Expand Down
29 changes: 24 additions & 5 deletions pytyut/CourseApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, connection: Connection):
def get_course_schedule(self) -> dict:
"""
获取自己的课表信息

:return: 返回课表json信息
"""
res = self.session.post(self.node + 'Tresources/A1Xskb/GetXsKb', headers=DEFAULT_HEADERS)
Expand All @@ -45,6 +46,7 @@ def get_course_schedule(self) -> dict:
def get_all_course_score(self, moreInformation=False) -> list:
"""
获取自己的课程成绩

:parameter moreInformation: 是否详细成绩 默认否
:return: 返回课程成绩json信息
"""
Expand Down Expand Up @@ -97,6 +99,7 @@ def get_test_info(self, semester: str = "now", moreInformation=False) -> list:
"""
获取考试安排信息
moreInformation=True时,semester可以传任意参数,不受影响。

:param moreInformation: 使用教务系统主页的简化接口
:param semester: 学年学期,如'2020-2021-1-1'表示2020-2021学年第一学期,同理'2020-2021-2-1'为第二学期
:return:返回考试安排的json信息
Expand Down Expand Up @@ -133,6 +136,7 @@ def get_test_info(self, semester: str = "now", moreInformation=False) -> list:
def get_course_schedule_by_bjh(self, semester: str, bjh: str) -> dict:
"""
根据学年学期专业班级获取的课表Json信息

:param semester: 学年学期,如 2022-2023学年秋季:'2022-2023-1-1'
:param bjh:班级号,专业班级简称
:return: dict 返回历届学院专业班级树的json信息
Expand All @@ -152,6 +156,7 @@ def get_selectable_course_list(self, semester: str = 'now') -> dict:
"""
获取该学期选课列表
如果没有可以选的课total就是0

:param semester: 学年学期
:return:dict 返回可以进行选课的科目列表(不是详情)
"""
Expand All @@ -171,6 +176,7 @@ def get_selectable_course_list(self, semester: str = 'now') -> dict:
def get_select_course_list(self, pid: str, semester: str = 'now') -> dict:
"""
获取选课课程列表

:param semester: 学年学期,不传值会自动获取
:param pid: 选课列表中的Id,比如0e902576-56cb-4e4f-a15a-3dce0b10a0b7(实际上是pid)
:return: list 返回
Expand Down Expand Up @@ -200,7 +206,8 @@ def get_selected_course_list(self) -> dict:
"""
获取已选择的课程列表
如果没有已经选的课total就是0
:return:dict 返回已经选课的科目列表(不是详情)

:return: dict 返回已经选课的科目列表(不是详情)
"""
req_url = self.node + 'Tschedule/C4Xkgl/GetYxkcListByXhAndZxjxjhh'
data = build_get_selected_course_list_request_data()
Expand All @@ -212,6 +219,7 @@ def get_selected_course_list(self) -> dict:
def get_set_cookie(self, headers: dict) -> str:
"""
访问一个伪装URL获取Set-Cookie 用于选课退课

:param headers: 请求头
:return: 字符串结果
"""
Expand All @@ -225,7 +233,12 @@ def get_set_cookie(self, headers: dict) -> str:
def select_course(self, json_info) -> dict:
"""
选课
:param json_info: 课程的json信息,如下所示:(注意,里面的数据一定不能传错,否则可能能选上课但是选的课的数据不对)

:param json_info: 课程的json信息(注意,里面的数据一定不能传错,否则可能能选上课但是选的课的数据不对)
:return: dict 返回操作成功的json数据
"""

"""
class_json_info = {
'xsxkList[0][Kch]': 'A0000111', # 课程号
'xsxkList[0][Kcm]': '中国近代人物研究', # 课程名
Expand All @@ -234,8 +247,8 @@ def select_course(self, json_info) -> dict:
'xsxkList[0][Bkskrl]': 6666, # 课程总共人数,必须转换为整数
'xsxkList[0][Xf]': '1', # 学分
}
:return:dict 返回操作成功的json数据
"""

headers = DEFAULT_HEADERS
headers.update(build_select_course_request_data(self.node))
req_url = self.node + 'Tschedule/C4Xkgl/XsxkSaveForm'
Expand All @@ -254,7 +267,13 @@ def select_course(self, json_info) -> dict:
def remove_course(self, json_info, course_Id):
"""
退课

:param json_info: 课程的json信息,如下所示:(注意,里面的数据一定不能传错,否则可能能选上课但是选的课的数据不对)
:param course_Id: 在self.get_chosen_course_list()方法返回的数据里面获取到的Id,注意不是pid,要区分
:return: dict 返回退选成功的json数据
"""

"""
class_json_info = {
'xsxkList[0][Kch]': 'A0000111', # 课程号
'xsxkList[0][Kcm]': '中国近代人物研究', # 课程名
Expand All @@ -263,9 +282,8 @@ def remove_course(self, json_info, course_Id):
'xsxkList[0][Bkskrl]': 6666, # 课程总共人数,必须转换为整数
'xsxkList[0][Xf]': '1', # 学分
}
:param course_Id: 在self.get_chosen_course_list()方法返回的数据里面获取到的Id,注意不是pid,要区分
:return:dict 返回退选成功的json数据
"""

headers = DEFAULT_HEADERS
headers.update(build_select_course_request_data(self.node))
req_url = self.node + 'Tschedule/C4Xkgl/XsxkRemoveForm'
Expand All @@ -284,6 +302,7 @@ def remove_course(self, json_info, course_Id):
def get_course_schedule_by_classroom(self, xnxq, xqh, jxlh, jash):
"""
通过教室信息获取教室课表

:param xnxq: str 学年学期
:param xqh: srt 校区号 01 迎西校区 02 虎峪校区 06实验 08 明向校区 09 校外 10 线上
:param jxlh: str 教学楼号
Expand Down
1 change: 1 addition & 0 deletions pytyut/Encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
def RSA_encrypt(user_name: str) -> str:
"""
RSA公钥加密

:param user_name: 账号
:return: 加密后的账号
"""
Expand Down
17 changes: 12 additions & 5 deletions pytyut/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
from .excepiton.NodeExcepiton import NodeException


def auto_node_choose() -> str:
def auto_node_choose(specific_url=None) -> str:
"""
自动确认登录节点
:return:登录节点的链接,
这个节点之前学生入口1是jxgl1.tyut.edu.cn,学生入口2是jxgl2.tyut.edu.cn
但是前几个月不知道怎么的域名不用了变成ip地址了,不知道学校在想什么
自动选择节点

:param specific_url: 指定节点链接(默认不使用)
:return: 返回可用节点链接
"""
if specific_url:
if test_node(specific_url):
return specific_url
else:
raise NodeException("指定节点不可用!")

urls = NODE_URLS
for i in urls:
if test_node(i):
Expand All @@ -27,6 +33,7 @@ def auto_node_choose() -> str:
def test_node(url) -> bool:
"""
检测节点是否正常

:param url: 需要检测的结点链接
:return: True or False,True为可用
"""
Expand Down