From 2f8c2eb3b67a8f70429a0fdd84e209a3a3886561 Mon Sep 17 00:00:00 2001 From: icyfeather Date: Tue, 27 Dec 2022 15:36:18 +0800 Subject: [PATCH] fix api change bugs --- .gitignore | 6 +++ README.md | 6 +++ modules/AutoCourseGrabbing.py | 82 ++++++++++++++++++++++++++++++----- ui/add.ui | 23 +++++++++- ui/start.ui | 23 +++++++++- win/MenuWin.py | 12 +++++ win/StartWin.py | 29 ++++++++++++- 7 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94540ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build +conf +dist +venv +mian +userinfo.json \ No newline at end of file diff --git a/README.md b/README.md index 3e20ecd..50c8f85 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ - ### 1.0 + - #### 1.1.0 + + ###### DEC 27 / 2022 + + > - 教务处更换了api,修改部分代码进行适配 + - #### 1.0.0 ###### DEC 15 / 2022 diff --git a/modules/AutoCourseGrabbing.py b/modules/AutoCourseGrabbing.py index 2e47d5c..be26d0e 100644 --- a/modules/AutoCourseGrabbing.py +++ b/modules/AutoCourseGrabbing.py @@ -2,10 +2,21 @@ import time import requests.exceptions +from PySide2.QtCore import QThread from PySide2.QtWidgets import QMessageBox, QTableWidgetItem from modules.utils import * +class Thread_start(QThread): + def __init__(self, sself): + super().__init__() + self.sself = sself + self.course_grabbing = sself.course_grabbing + + def run(self) -> None: + self.course_grabbing.start(self.sself) + + class AutoCourseGrabbing: def __init__(self): @@ -16,6 +27,16 @@ def __init__(self): self.data_list = [] def show_course_in_table(self, data_list, sself): + """ + 显示课程信息 + :param data_list: + :param sself: + :return: + """ + if not isinstance(data_list,list): + data_list = [data_list] + print(data_list) + sself.ui.table.setRowCount(len(data_list)) idx = 0 for classData in data_list: # 课程序号 --------------------------------- @@ -74,6 +95,7 @@ def show_course_in_table(self, data_list, sself): classTech = str(classData['skjs'][0:9]) except (ValueError, TypeError, Exception): classTech = "未知教师" + sself.ui.table.setItem(idx, 0, QTableWidgetItem(classUUID)) sself.ui.table.setItem(idx, 1, QTableWidgetItem(className)) sself.ui.table.setItem(idx, 2, QTableWidgetItem(classArea)) @@ -87,6 +109,11 @@ def show_course_in_table(self, data_list, sself): idx += 1 def selectRes(self, sself): + """ + 选课结果 + :param sself: + :return: + """ try: res_data = http_main.get(http_urls_select_res) except requests.exceptions.ConnectionError or BaseException: @@ -128,11 +155,19 @@ def selectRes(self, sself): idx += 1 def query_course(self, sself): + """ + 查询课程 + :param sself: + :return: + """ query_content = sself.ui.query_info.text() query_data = { - "searchtj": query_content, - "xq": 0, - "jc": 0, + "kkxsh": "", + "kch": "", + "kcm": query_content, + "skjs": "", + "xq": "0", + "jc": "0", "kclbdm": "" } try: @@ -156,12 +191,16 @@ def query_course(self, sself): print("网络错误") QMessageBox.about(sself.ui, '[错误]', '网络错误') return -2 - sself.ui.table.setRowCount(len(data_list)) self.data_list = data_list self.fxid = json.loads(raw_data['yxkclist'])[0]['programPlanNumber'] self.show_course_in_table(data_list, sself) def add_course(self, sself): + """ + 添加课程 + :param sself: + :return: + """ selected_row = sself.ui.table.selectedItems() print("选中的行数") selected_row = [e.row() for e in selected_row] @@ -189,17 +228,26 @@ def add_course(self, sself): QMessageBox.about(sself.ui, '[成功]', '成功将' + str(self.numc[sself.ui.query_info.text()]) + '门课程添加进列表') def start(self, sself): + """ + 开始抢课 + :param sself: + :return: + """ + sself.ui.start_btn.setEnabled(False) + # 查看当前添加的课程列表 print(self.data) loop_time = sself.ui.time.text() if len(self.data) == 0: print("[尚未添加课程]:请先添加课程,然后再重新开始抢课") - QMessageBox.about(sself.ui, '[提示]', '[尚未添加课程]:请先添加课程,然后再重新开始抢课') + # QMessageBox.about(sself.ui, '[提示]', '[尚未添加课程]:请先添加课程,然后再重新开始抢课') + sself.communicate.message.emit('[尚未添加课程]:请先添加课程,然后再重新开始抢课') return -1 flag = 0 count = 0 begin_time = time.time() last_time = time.time() while flag == 0: + count += 1 all_time = str((time.time() - begin_time) // 3600) + "时" + str( ((time.time() - begin_time) % 3600) // 60) + "分" + str(((time.time() - begin_time) % 60) // 1) + "秒" lunxun = str(int((time.time() - last_time) * 1000)) @@ -208,6 +256,10 @@ def start(self, sself): " 总共耗时:" + all_time, " 轮询速度:" + str(lunxun) + "ms/次", " 设定速度:" + str(loop_time) + "s/次") + sself.communicate.top_bar.emit(" 当前次数:" + str(count) + + " 总共耗时:" + all_time + + " 轮询速度:" + str(lunxun) + "ms/次") + time.sleep(int(loop_time) - 1) try: addles_datr = http_main.get(http_urls_course_select) @@ -233,7 +285,7 @@ def start(self, sself): addles_list = addles_tabs['rwRxkZlList'] else: print("网络错误") - QMessageBox.about(sself.ui, '[错误]', '网络错误') + sself.communicate.message.emit('网络错误') return -2 addles_nums = 0 for addles_loop in addles_list: @@ -247,6 +299,7 @@ def start(self, sself): and self.data[addles_name]['dat2'][addles_tttp] == addles_loop['jasm'] \ and self.data[addles_name]['dat3'][addles_tttp] == addles_loop['skjs'] \ and self.data[addles_name]['dat4'][addles_tttp] == addles_loop['kxh']: + # print(addles_loop) self.show_course_in_table(addles_loop, sself) if int(addles_loop['bkskyl']) > 0: zxyk_name = "" @@ -276,12 +329,14 @@ def start(self, sself): continue if addles_data.text.find("ok") != -1: print(addles_loop['kcm'] + "抢课成功") - QMessageBox.about(sself.ui, '[成功]', addles_loop['kcm'] + '抢课成功') + # QMessageBox.about(sself.ui, '[成功]', addles_loop['kcm'] + '抢课成功') + sself.communicate.message.emit(addles_loop['kcm'] + '抢课成功') self.data.pop(addles_name) data_change = True else: print("抢课失败") - QMessageBox.about(sself.ui, '[失败]', addles_loop['kcm'] + '抢课失败') + # QMessageBox.about(sself.ui, '[失败]', addles_loop['kcm'] + '抢课失败') + sself.communicate.message.emit(addles_loop['kcm'] + '抢课失败') time.sleep(5) flag = 0 break @@ -302,12 +357,19 @@ def start(self, sself): return -1 except requests.exceptions.ConnectionError: print("网络错误") - QMessageBox.about(sself.ui, '[错误]', '网络错误') + # QMessageBox.about(sself.ui, '[错误]', '网络错误') + sself.communicate.message.emit('网络错误') continue print("抢课全部结束") - QMessageBox.about(sself.ui, '[成功]', '抢课全部结束') + # QMessageBox.about(sself.ui, '[成功]', '抢课全部结束') + sself.communicate.message.emit('抢课全部结束') def delete(self, sself): + """ + 退课 + :param sself: + :return: + """ selected_row = sself.ui.table.selectedItems() print("选中的行数") selected_row = [e.row() for e in selected_row] diff --git a/ui/add.ui b/ui/add.ui index 1072978..eba00c1 100644 --- a/ui/add.ui +++ b/ui/add.ui @@ -17,9 +17,9 @@ 30 - 70 + 100 1101 - 531 + 501 @@ -96,6 +96,25 @@ 添加 + + + + 50 + 60 + 441 + 31 + + + + + 宋体 + 16 + + + + 提示:不同的课程请用不同的关键词搜索添加 + + diff --git a/ui/start.ui b/ui/start.ui index c9cf448..b65ba1c 100644 --- a/ui/start.ui +++ b/ui/start.ui @@ -17,9 +17,9 @@ 40 - 60 + 110 1101 - 531 + 481 @@ -77,6 +77,25 @@ + + + + 50 + 70 + 1081 + 31 + + + + + 宋体 + 12 + + + + 当前次数: 总共耗时: 轮询速度: + + diff --git a/win/MenuWin.py b/win/MenuWin.py index 26c1055..19a61a1 100644 --- a/win/MenuWin.py +++ b/win/MenuWin.py @@ -17,17 +17,29 @@ def __init__(self): def go_selected(self): + """ + 已选课程 + :return: + """ global se_win se_win = SelectedWin(self) se_win.ui.show() def go_add(self): + """ + 添加课程 + :return: + """ global add_win add_win = AddWin(self) add_win.ui.show() def go_start(self): + """ + 开始抢课 + :return: + """ global start_win start_win = StartWin(self) start_win.ui.show() diff --git a/win/StartWin.py b/win/StartWin.py index 2194fe5..fc01fcd 100644 --- a/win/StartWin.py +++ b/win/StartWin.py @@ -1,15 +1,42 @@ +import threading + +from PySide2.QtCore import Signal, Slot, QObject from PySide2.QtUiTools import QUiLoader +from PySide2.QtWidgets import QLabel, QMessageBox + +from modules.AutoCourseGrabbing import Thread_start + +class Communicate(QObject): + top_bar = Signal(str) + message = Signal(str) class StartWin: def __init__(self, sself): super().__init__() + self.th_start = None self.ui = QUiLoader().load('./ui/start.ui') self.ui.table.setColumnCount(10) self.ui.table.setHorizontalHeaderLabels( ["课程编号", "课程名", "校区", "课余量", "位置", "教室", "周数", "星期", "时间", "教师"]) + self.ui.start_btn.setEnabled(True) self.ui.start_btn.clicked.connect(self.start) self.course_grabbing = sself.course_grabbing + self.communicate = Communicate() + self.communicate.top_bar.connect(self.show_running_info) + self.communicate.message.connect(self.show_messagebox) + + @Slot(str) + def show_messagebox(self, content): + print(content) + QMessageBox.about(self.ui, '[提示]', content) + + @Slot(str) + def show_running_info(self, content): + print(content) + self.ui.running_info.setText(content) def start(self): - self.course_grabbing.start(self) \ No newline at end of file + self.th_start = Thread_start(self) + self.th_start.start() + # self.course_grabbing.start(self) \ No newline at end of file