Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
fix api change bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
icyfeather committed Dec 27, 2022
1 parent 28edede commit 2f8c2eb
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
conf
dist
venv
mian
userinfo.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@

- ### 1.0

- #### 1.1.0

###### DEC 27 / 2022

> - 教务处更换了api,修改部分代码进行适配
- #### 1.0.0

###### DEC 15 / 2022
Expand Down
82 changes: 72 additions & 10 deletions modules/AutoCourseGrabbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
# 课程序号 ---------------------------------
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
23 changes: 21 additions & 2 deletions ui/add.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<y>100</y>
<width>1101</width>
<height>531</height>
<height>501</height>
</rect>
</property>
</widget>
Expand Down Expand Up @@ -96,6 +96,25 @@
<string>添加</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>50</x>
<y>60</y>
<width>441</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>宋体</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>提示:不同的课程请用不同的关键词搜索添加</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
23 changes: 21 additions & 2 deletions ui/start.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<property name="geometry">
<rect>
<x>40</x>
<y>60</y>
<y>110</y>
<width>1101</width>
<height>531</height>
<height>481</height>
</rect>
</property>
</widget>
Expand Down Expand Up @@ -77,6 +77,25 @@
</font>
</property>
</widget>
<widget class="QLabel" name="running_info">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>1081</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>当前次数: 总共耗时: 轮询速度: </string>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
12 changes: 12 additions & 0 deletions win/MenuWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
29 changes: 28 additions & 1 deletion win/StartWin.py
Original file line number Diff line number Diff line change
@@ -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)
self.th_start = Thread_start(self)
self.th_start.start()
# self.course_grabbing.start(self)

0 comments on commit 2f8c2eb

Please sign in to comment.