小闲答题数据下载功能放到工具面板上
This commit is contained in:
parent
2983dc1308
commit
6c88ec141e
|
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>题库工具面板(PyQt)-20240301</string>
|
||||
<string>题库工具面板v3-20240417</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
|
|
@ -53,6 +53,8 @@
|
|||
<addaction name="action_hbsy"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_tjjc"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_xzxx"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_shiyong">
|
||||
<property name="title">
|
||||
|
|
@ -205,6 +207,11 @@
|
|||
<string>根据正确率选择题号</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_xzxx">
|
||||
<property name="text">
|
||||
<string>下载小闲平台答题数据</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ class Ui_MainWindow(object):
|
|||
self.action_hist.setObjectName(u"action_hist")
|
||||
self.action_xzth = QAction(MainWindow)
|
||||
self.action_xzth.setObjectName(u"action_xzth")
|
||||
self.action_xzxx = QAction(MainWindow)
|
||||
self.action_xzxx.setObjectName(u"action_xzxx")
|
||||
self.centralwidget = QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName(u"centralwidget")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
|
|
@ -117,6 +119,8 @@ class Ui_MainWindow(object):
|
|||
self.menu_weihu.addAction(self.action_hbsy)
|
||||
self.menu_weihu.addSeparator()
|
||||
self.menu_weihu.addAction(self.action_tjjc)
|
||||
self.menu_weihu.addSeparator()
|
||||
self.menu_weihu.addAction(self.action_xzxx)
|
||||
self.menu_shiyong.addAction(self.action_sxth)
|
||||
self.menu_shiyong.addAction(self.action_xzth)
|
||||
self.menu_shiyong.addSeparator()
|
||||
|
|
@ -138,7 +142,7 @@ class Ui_MainWindow(object):
|
|||
# setupUi
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u9898\u5e93\u5de5\u5177\u9762\u677f(PyQt)-20240301", None))
|
||||
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u9898\u5e93\u5de5\u5177\u9762\u677fv3-20240417", None))
|
||||
self.action_kxth.setText(QCoreApplication.translate("MainWindow", u"\u5bfb\u627e\u7a7a\u95f2\u9898\u53f7", None))
|
||||
self.action_xtbd.setText(QCoreApplication.translate("MainWindow", u"\u65b0\u9898\u6bd4\u5bf9", None))
|
||||
self.action_plsl.setText(QCoreApplication.translate("MainWindow", u"\u6279\u91cf\u6536\u5f55\u65b0\u9898", None))
|
||||
|
|
@ -162,6 +166,7 @@ class Ui_MainWindow(object):
|
|||
self.action_bjtm.setText(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91\u9898\u76ee", None))
|
||||
self.action_hist.setText(QCoreApplication.translate("MainWindow", u"\u751f\u6210\u76f4\u65b9\u56fe\u4ee3\u7801", None))
|
||||
self.action_xzth.setText(QCoreApplication.translate("MainWindow", u"\u6839\u636e\u6b63\u786e\u7387\u9009\u62e9\u9898\u53f7", None))
|
||||
self.action_xzxx.setText(QCoreApplication.translate("MainWindow", u"\u4e0b\u8f7d\u5c0f\u95f2\u5e73\u53f0\u7b54\u9898\u6570\u636e", None))
|
||||
self.menu_luru.setTitle(QCoreApplication.translate("MainWindow", u"\u5f55\u5165", None))
|
||||
self.menu_weihu.setTitle(QCoreApplication.translate("MainWindow", u"\u7ef4\u62a4", None))
|
||||
self.menu_shiyong.setTitle(QCoreApplication.translate("MainWindow", u"\u4f7f\u7528", None))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
################################################################################
|
||||
## Form generated from reading UI file '下载小闲答题数据.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.6.2
|
||||
##
|
||||
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
################################################################################
|
||||
|
||||
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
|
||||
QMetaObject, QObject, QPoint, QRect,
|
||||
QSize, QTime, QUrl, Qt)
|
||||
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
||||
QFont, QFontDatabase, QGradient, QIcon,
|
||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||
from PySide6.QtWidgets import (QApplication, QHeaderView, QLabel, QLineEdit,
|
||||
QPushButton, QSizePolicy, QTableWidget, QTableWidgetItem,
|
||||
QWidget)
|
||||
|
||||
class Ui_Form(object):
|
||||
def setupUi(self, Form):
|
||||
if not Form.objectName():
|
||||
Form.setObjectName(u"Form")
|
||||
Form.resize(489, 636)
|
||||
self.pushButton_chrome = QPushButton(Form)
|
||||
self.pushButton_chrome.setObjectName(u"pushButton_chrome")
|
||||
self.pushButton_chrome.setGeometry(QRect(10, 10, 75, 24))
|
||||
self.pushButton_driver = QPushButton(Form)
|
||||
self.pushButton_driver.setObjectName(u"pushButton_driver")
|
||||
self.pushButton_driver.setGeometry(QRect(10, 50, 75, 24))
|
||||
self.pushButton_outputfolder = QPushButton(Form)
|
||||
self.pushButton_outputfolder.setObjectName(u"pushButton_outputfolder")
|
||||
self.pushButton_outputfolder.setGeometry(QRect(10, 90, 75, 24))
|
||||
self.label_chrome = QLabel(Form)
|
||||
self.label_chrome.setObjectName(u"label_chrome")
|
||||
self.label_chrome.setGeometry(QRect(90, 10, 221, 21))
|
||||
self.label_driver = QLabel(Form)
|
||||
self.label_driver.setObjectName(u"label_driver")
|
||||
self.label_driver.setGeometry(QRect(90, 50, 221, 21))
|
||||
self.label_outputfolder = QLabel(Form)
|
||||
self.label_outputfolder.setObjectName(u"label_outputfolder")
|
||||
self.label_outputfolder.setGeometry(QRect(90, 90, 221, 21))
|
||||
self.pushButton_openbrowser = QPushButton(Form)
|
||||
self.pushButton_openbrowser.setObjectName(u"pushButton_openbrowser")
|
||||
self.pushButton_openbrowser.setGeometry(QRect(10, 130, 71, 51))
|
||||
self.pushButton_login = QPushButton(Form)
|
||||
self.pushButton_login.setObjectName(u"pushButton_login")
|
||||
self.pushButton_login.setGeometry(QRect(90, 130, 71, 51))
|
||||
self.pushButton_exec = QPushButton(Form)
|
||||
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||
self.pushButton_exec.setGeometry(QRect(280, 130, 201, 51))
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
self.pushButton_exec.setFont(font)
|
||||
self.label = QLabel(Form)
|
||||
self.label.setObjectName(u"label")
|
||||
self.label.setGeometry(QRect(330, 10, 54, 16))
|
||||
self.label_2 = QLabel(Form)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
self.label_2.setGeometry(QRect(330, 50, 54, 16))
|
||||
self.label_3 = QLabel(Form)
|
||||
self.label_3.setObjectName(u"label_3")
|
||||
self.label_3.setGeometry(QRect(330, 90, 71, 16))
|
||||
self.lineEdit_startdate = QLineEdit(Form)
|
||||
self.lineEdit_startdate.setObjectName(u"lineEdit_startdate")
|
||||
self.lineEdit_startdate.setGeometry(QRect(390, 10, 91, 20))
|
||||
self.lineEdit_enddate = QLineEdit(Form)
|
||||
self.lineEdit_enddate.setObjectName(u"lineEdit_enddate")
|
||||
self.lineEdit_enddate.setGeometry(QRect(390, 50, 91, 20))
|
||||
self.lineEdit_graderegex = QLineEdit(Form)
|
||||
self.lineEdit_graderegex.setObjectName(u"lineEdit_graderegex")
|
||||
self.lineEdit_graderegex.setGeometry(QRect(410, 90, 71, 20))
|
||||
self.pushButton_getlist = QPushButton(Form)
|
||||
self.pushButton_getlist.setObjectName(u"pushButton_getlist")
|
||||
self.pushButton_getlist.setGeometry(QRect(170, 130, 101, 51))
|
||||
self.tableWidget = QTableWidget(Form)
|
||||
if (self.tableWidget.columnCount() < 2):
|
||||
self.tableWidget.setColumnCount(2)
|
||||
__qtablewidgetitem = QTableWidgetItem()
|
||||
self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
|
||||
__qtablewidgetitem1 = QTableWidgetItem()
|
||||
self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
|
||||
self.tableWidget.setObjectName(u"tableWidget")
|
||||
self.tableWidget.setGeometry(QRect(10, 190, 471, 431))
|
||||
|
||||
self.retranslateUi(Form)
|
||||
|
||||
QMetaObject.connectSlotsByName(Form)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u4e0b\u8f7d\u5c0f\u95f2\u7b54\u9898\u7eb8", None))
|
||||
self.pushButton_chrome.setText(QCoreApplication.translate("Form", u"chrome\u8def\u5f84", None))
|
||||
self.pushButton_driver.setText(QCoreApplication.translate("Form", u"driver\u8def\u5f84", None))
|
||||
self.pushButton_outputfolder.setText(QCoreApplication.translate("Form", u"\u8f93\u51fa\u8def\u5f84", None))
|
||||
self.label_chrome.setText(QCoreApplication.translate("Form", u"\u6b64\u5904\u663e\u793achrome.exe\u7684\u8def\u5f84", None))
|
||||
self.label_driver.setText(QCoreApplication.translate("Form", u"\u6b64\u5904\u663e\u793achrome webdriver\u7684\u8def\u5f84", None))
|
||||
self.label_outputfolder.setText(QCoreApplication.translate("Form", u"\u6b64\u5904\u663e\u793a\u8f93\u51fa\u7684zip\u6587\u4ef6\u7684\u8def\u5f84", None))
|
||||
self.pushButton_openbrowser.setText(QCoreApplication.translate("Form", u"\u5f00\u542f\u6d4f\u89c8\u5668", None))
|
||||
self.pushButton_login.setText(QCoreApplication.translate("Form", u"\u767b\u5f55", None))
|
||||
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u4e0b\u8f7d\u7b54\u9898\u60c5\u51b5", None))
|
||||
self.label.setText(QCoreApplication.translate("Form", u"\u8d77\u59cb\u65e5\u671f", None))
|
||||
self.label_2.setText(QCoreApplication.translate("Form", u"\u7ec8\u6b62\u65e5\u671f", None))
|
||||
self.label_3.setText(QCoreApplication.translate("Form", u"\u5e74\u7ea7(regex)", None))
|
||||
self.lineEdit_startdate.setPlaceholderText(QCoreApplication.translate("Form", u"yyyymmdd", None))
|
||||
self.lineEdit_enddate.setPlaceholderText(QCoreApplication.translate("Form", u"yyyymmdd", None))
|
||||
self.lineEdit_graderegex.setPlaceholderText(QCoreApplication.translate("Form", u"\u9ad8[\u4e00\u4e8c]", None))
|
||||
self.pushButton_getlist.setText(QCoreApplication.translate("Form", u"\u83b7\u53d6\u7b54\u9898\u5361\u5217\u8868", None))
|
||||
___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
|
||||
___qtablewidgetitem.setText(QCoreApplication.translate("Form", u"\u7b54\u9898\u7eb8\u540d\u79f0", None));
|
||||
___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
|
||||
___qtablewidgetitem1.setText(QCoreApplication.translate("Form", u"\u5df2\u4e0b\u8f7d", None));
|
||||
# retranslateUi
|
||||
|
||||
|
|
@ -2462,7 +2462,7 @@ def AutoAssignTagNotoLaTeX(newlist,allsamelist,allrelatedlist):
|
|||
print("正在生成简化题目的字典...")
|
||||
treateddict = treat_dict()
|
||||
print("简化题目字典生成完毕.")
|
||||
for id in newlist:
|
||||
for id in tqdm.tqdm(newlist):
|
||||
samelist = findsru(id,allsamelist)
|
||||
relatedlist = findsru(id,allrelatedlist)
|
||||
if not samelist == []:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,335 @@
|
|||
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetItem
|
||||
from PySide6.QtGui import QColor
|
||||
from Ui_下载小闲答题数据 import Ui_Form
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
import re,os,sys
|
||||
from datetime import datetime
|
||||
import numpy as np
|
||||
from time import sleep
|
||||
|
||||
|
||||
def GetPageInfo(driver): #学情报告页面, 显示页码和总页数
|
||||
pageinfo = driver.find_element(By.CSS_SELECTOR,"[class*=styles__page___]").text
|
||||
return pageinfo
|
||||
|
||||
|
||||
def SelectNext(driver): # 在打开后的报告页面选择下一个班级
|
||||
try:
|
||||
openlist = driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div[1]/div[2]/div/div/div")
|
||||
sleep(0.1)
|
||||
openlist.click()
|
||||
sleep(0.1)
|
||||
openlist.send_keys(Keys.ARROW_DOWN)
|
||||
sleep(0.1)
|
||||
openlist.send_keys(Keys.ENTER)
|
||||
sleep(0.3)
|
||||
return driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div[1]/div[2]/div/div/div").text
|
||||
except:
|
||||
return 1
|
||||
|
||||
def GetDate(driver): #显示当前班级的提交时间
|
||||
commit_date = driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div[1]/div[2]/span[2]").text
|
||||
year,month,date = re.findall(r"(\d{4})-(\d{2})-(\d{2})",commit_date)[0]
|
||||
return year+month+date
|
||||
|
||||
def GetCommitInfo(driver): #获取报告页面的班级及提交日期信息
|
||||
commit_dict = {}
|
||||
classname = SelectNext(driver)
|
||||
sleep(0.5)
|
||||
while not classname in commit_dict.keys():
|
||||
commit_date = GetDate(driver)
|
||||
if not classname == 1:
|
||||
commit_dict[classname] = commit_date
|
||||
classname = SelectNext(driver)
|
||||
else:
|
||||
classname = SelectNext(driver)
|
||||
return commit_dict
|
||||
|
||||
def ToIntTime(string):
|
||||
date_obj = datetime.strptime(string, "%Y%m%d")
|
||||
int_time = int(date_obj.timestamp())
|
||||
return int_time
|
||||
|
||||
def MedianCommitDate(adict):
|
||||
return datetime.fromtimestamp(np.median([ToIntTime(adict[t]) for t in adict.keys()])).strftime("%Y%m%d")
|
||||
|
||||
def gotopagenum(driver,num):
|
||||
pagecontrol = driver.find_element(By.CSS_SELECTOR,"[class*=styles__pagination___]")
|
||||
pageinput = pagecontrol.find_element(By.CSS_SELECTOR,"input[type=text]")
|
||||
pageinput.clear()
|
||||
submitbutton = pagecontrol.find_element(By.CSS_SELECTOR,"[class*=tyles__button___]")
|
||||
pageinput.send_keys(str(1))
|
||||
submitbutton.click()
|
||||
sleep(0.5)
|
||||
pageinput.clear()
|
||||
sleep(0.1)
|
||||
pageinput.send_keys(str(num))
|
||||
submitbutton.click()
|
||||
sleep(0.5)
|
||||
|
||||
def ClickBack(driver): # 点击返回按钮
|
||||
backbutton = driver.find_element(By.CSS_SELECTOR,'[class*=styles__back]') # 点击返回
|
||||
backbutton.click()
|
||||
sleep(1)
|
||||
|
||||
def GetHomeworkNames(driver,starting_date = "20000101"):
|
||||
hwk_list = []
|
||||
homework_roots = driver.find_elements(By.CSS_SELECTOR,'[class*=styles__reportList]')
|
||||
for homework_root in homework_roots:
|
||||
name = homework_root.find_element(By.CSS_SELECTOR,'[class*=styles__name]').text
|
||||
date_raw = homework_root.find_element(By.CSS_SELECTOR,'[class*=styles__time]').text
|
||||
date = re.findall(r"\d{4}-\d{2}-\d{2}",date_raw)[0].replace("-","")
|
||||
time = re.findall(r"\d{2}:\d{2}:\d{2}",date_raw)[0].replace(":","")
|
||||
grade = homework_root.find_element(By.CSS_SELECTOR,'[class*=styles__grades]').text[3:]
|
||||
if date >= starting_date:
|
||||
hwk_list.append({"name": name, "date": date, "time": time, "grade": grade})
|
||||
return hwk_list
|
||||
|
||||
def GetHomeworkRoots(driver): #找到页面上所有作业考试的root
|
||||
homework_roots = driver.find_elements(By.CSS_SELECTOR,'[class*=styles__reportList]')
|
||||
return homework_roots
|
||||
|
||||
def ClickDetail(root): #点击查看详情
|
||||
root.find_element(By.XPATH,"div[2]/div[2]").click()
|
||||
|
||||
def ClickDownload(root): #点击报表
|
||||
root.find_element(By.XPATH,"div[2]/div[3]").click()
|
||||
|
||||
def StartandEndDownload(driver):
|
||||
driver.find_element(By.XPATH,"/html/body/div[4]/div/div[2]/div/div[2]/div[3]/div/button[2]").click()
|
||||
QuitDownload(driver)
|
||||
|
||||
def QuitDownload(driver): #退出下载对话框
|
||||
while driver.find_element(By.XPATH,"/html/body/div[4]/div/div[2]/div/div[2]/div[3]/div/button[1]").text == '取 消':
|
||||
try:
|
||||
sleep(0.5)
|
||||
driver.find_element(By.XPATH,"/html/body/div[4]/div/div[2]/div/div[2]/div[3]/div/button[1]").click()
|
||||
except:
|
||||
pass
|
||||
|
||||
def GenerateCommitMessages(driver,index): #在班级报告页面逐一读取页面上的指定作业的名称和计算中位提交日期
|
||||
page_info = GetPageInfo(driver)
|
||||
page = page_info[:page_info.index("/")]
|
||||
roots = GetHomeworkRoots(driver)
|
||||
root = roots[index-1]
|
||||
# root_text = root.text
|
||||
# homework_name = root_text.split("\n")[1]
|
||||
ClickDetail(root)
|
||||
adict = GetCommitInfo(driver)
|
||||
# print(homework_name)
|
||||
message = MedianCommitDate(adict)
|
||||
sleep(0.1)
|
||||
ClickBack(driver)
|
||||
sleep(0.5)
|
||||
gotopagenum(driver,page)
|
||||
sleep(0.5)
|
||||
return message
|
||||
|
||||
def DownloadZipwithDetail(driver,index): #下载页面上的指定zip文件, 并返回中位上传时间
|
||||
page_info = GetPageInfo(driver)
|
||||
page = page_info[:page_info.index("/")]
|
||||
roots = GetHomeworkRoots(driver)
|
||||
root = roots[index-1]
|
||||
root_text = root.text
|
||||
homework_name = root_text.split("\n")[1]
|
||||
ClickDownload(root)
|
||||
sleep(0.5)
|
||||
StartandEndDownload(driver)
|
||||
print(f"已下载: {homework_name}")
|
||||
sleep(0.5)
|
||||
QuitDownload(driver)
|
||||
ClickDetail(root)
|
||||
adict = GetCommitInfo(driver)
|
||||
message = MedianCommitDate(adict)
|
||||
sleep(0.1)
|
||||
ClickBack(driver)
|
||||
sleep(0.5)
|
||||
gotopagenum(driver,page)
|
||||
sleep(0.5)
|
||||
return message
|
||||
|
||||
def RenameRecentzip(folder,message): #将folder中最新的zip文件名加上(message)
|
||||
filelist = os.listdir(folder)
|
||||
filelist.sort(key = lambda x:os.path.getmtime(os.path.join(folder,x)),reverse = True)
|
||||
filepath = os.path.join(folder,filelist[0])
|
||||
renamedfilepath = filepath[:-4]+f"({message}).zip"
|
||||
try:
|
||||
os.rename(filepath,renamedfilepath)
|
||||
print(f"已重命名为: {os.path.split(renamedfilepath)[-1]}")
|
||||
except:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def DownloadZips(driver,alist=[]): #下载页面上的指定zip文件
|
||||
page_info = GetPageInfo(driver)
|
||||
page = page_info[:page_info.index("/")]
|
||||
roots_len = len(GetHomeworkRoots(driver))
|
||||
if alist == []:
|
||||
rangelist = range(roots_len)
|
||||
else:
|
||||
rangelist = alist.copy()
|
||||
for i in rangelist:
|
||||
roots = GetHomeworkRoots(driver)
|
||||
root = roots[i]
|
||||
root_text = root.text
|
||||
homework_name = root_text.split("\n")[1]
|
||||
ClickDownload(root)
|
||||
sleep(0.5)
|
||||
StartandEndDownload(driver)
|
||||
print(f"已下载: {homework_name}")
|
||||
sleep(0.5)
|
||||
gotopagenum(driver,page)
|
||||
sleep(0.5)
|
||||
|
||||
def DownloadandRenameZips(driver,message,folder,index): #下载页面上的指定zip文件
|
||||
page_info = GetPageInfo(driver)
|
||||
page = page_info[:page_info.index("/")]
|
||||
roots = GetHomeworkRoots(driver)
|
||||
root = roots[index-1]
|
||||
print(root.text)
|
||||
ClickDownload(root)
|
||||
sleep(0.5)
|
||||
StartandEndDownload(driver)
|
||||
sleep(5)
|
||||
filelist = os.listdir(folder)
|
||||
filelist.sort(key = lambda x:os.path.getmtime(os.path.join(folder,x)),reverse = True)
|
||||
filepath = os.path.join(folder,filelist[0])
|
||||
renamedfilepath = filepath[:-4]+f"({message}).zip"
|
||||
os.rename(filepath,renamedfilepath)
|
||||
print(f"已重命名为: {os.path.split(renamedfilepath)[-1]}")
|
||||
sleep(0.5)
|
||||
gotopagenum(driver,page)
|
||||
sleep(0.5)
|
||||
|
||||
def getIndices(string):
|
||||
if string.strip() == "":
|
||||
return []
|
||||
else:
|
||||
string_list = [int(i)-1 for i in string.strip().split(",")]
|
||||
return string_list
|
||||
|
||||
def GetValidHomeworks(driver,startdate,enddate,graderegex): #在所有作业中找到在startdate,enddate中符合graderegex年级的作业, 返回(作业信息,页码)的列表
|
||||
validhomeworks = []
|
||||
gotopagenum(driver,1)
|
||||
sleep(2)
|
||||
endflag = False
|
||||
while not endflag:
|
||||
currentpage = int(re.findall("^([\d]+)/",GetPageInfo(driver))[0])
|
||||
homeworkinfo = GetHomeworkNames(driver)
|
||||
for item in homeworkinfo:
|
||||
if re.findall(graderegex,item["grade"])!= [] and startdate <= item["date"] <= enddate:
|
||||
validhomeworks.append((item,currentpage))
|
||||
print(item)
|
||||
if startdate > item["date"]:
|
||||
endflag = True
|
||||
break
|
||||
gotopagenum(driver,currentpage+1)
|
||||
sleep(2)
|
||||
return validhomeworks[-1::-1]
|
||||
|
||||
|
||||
def gethmwkIndexonPage(driver,hmwkinfo): #在当前页面寻找作业位置, 返回位置(1-10), 若未找到则返回-1
|
||||
homeworks = GetHomeworkNames(driver)
|
||||
count = 1
|
||||
for h in homeworks:
|
||||
if h == hmwkinfo:
|
||||
return count
|
||||
count += 1
|
||||
return -1
|
||||
|
||||
class MyWindow(QWidget,Ui_Form):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.bind()
|
||||
|
||||
def bind(self):
|
||||
self.pushButton_chrome.clicked.connect(self.getchromePath)
|
||||
self.pushButton_driver.clicked.connect(self.getdriverPath)
|
||||
self.pushButton_outputfolder.clicked.connect(self.getoutputfolder)
|
||||
self.pushButton_openbrowser.clicked.connect(self.openbrowser)
|
||||
self.pushButton_login.clicked.connect(self.login)
|
||||
self.pushButton_getlist.clicked.connect(self.getlist)
|
||||
self.pushButton_exec.clicked.connect(self.exec)
|
||||
self.tableWidget.setColumnWidth(0,350)
|
||||
self.tableWidget.setColumnWidth(1,80)
|
||||
def getchromePath(self):
|
||||
pathlist = QFileDialog.getOpenFileName(self,"选择文件",".","chrome.exe文件(chrome.exe);;所有文件(*)")
|
||||
self.label_chrome.setText(pathlist[0])
|
||||
self.chromepath = pathlist[0]
|
||||
def getdriverPath(self):
|
||||
pathlist = QFileDialog.getOpenFileName(self,"选择文件",".","chromedriver.exe文件(chromedriver.exe);;所有文件(*)")
|
||||
self.label_driver.setText(pathlist[0])
|
||||
self.driverpath = pathlist[0]
|
||||
def getoutputfolder(self):
|
||||
self.outputfolder = QFileDialog.getExistingDirectory(None, "选择文件夹")
|
||||
if sys.platform == "win32":
|
||||
self.outputfolder = self.outputfolder.replace("/","\\")
|
||||
self.label_outputfolder.setText(self.outputfolder)
|
||||
def openbrowser(self):
|
||||
service = Service(executable_path=self.driverpath)
|
||||
options = webdriver.ChromeOptions()
|
||||
options.binary_location = self.chromepath
|
||||
prefs = {"download.default_directory": self.outputfolder}
|
||||
options.add_experimental_option("prefs", prefs)
|
||||
self.driver = webdriver.Chrome(service= service,options = options)
|
||||
self.driver.get("http://ls.xiaoxianai.cn")
|
||||
def login(self):
|
||||
loginform = self.driver.find_element(By.XPATH,'//*[@id="container"]/div/div/form')
|
||||
loginlist = loginform.find_elements(By.TAG_NAME,"div")
|
||||
loginlist[1].find_element(By.TAG_NAME,"input").send_keys("16621337584")
|
||||
loginlist[2].find_element(By.TAG_NAME,"input").send_keys("password")
|
||||
loginform.find_element(By.TAG_NAME,"button").click()
|
||||
def getlist(self):
|
||||
self.homeworklist = GetValidHomeworks(self.driver,self.lineEdit_startdate.text(),self.lineEdit_enddate.text(),self.lineEdit_graderegex.text())
|
||||
for i in range(len(self.homeworklist)):
|
||||
self.tableWidget.insertRow(i)
|
||||
self.tableWidget.setItem(i,0,QTableWidgetItem(f"{self.homeworklist[i][0]['name']} / {self.homeworklist[i][0]['grade']}"))
|
||||
self.tableWidget.setItem(i,1,QTableWidgetItem(""))
|
||||
def exec(self):
|
||||
i = 0
|
||||
for hmwk,page in self.homeworklist:
|
||||
foundhmwk = False
|
||||
downloaded = False
|
||||
for p in range(page+1,0,-1):
|
||||
gotopagenum(self.driver,p)
|
||||
sleep(2)
|
||||
hmwkindex = gethmwkIndexonPage(self.driver,hmwk)
|
||||
if hmwkindex > 0:
|
||||
foundhmwk = True
|
||||
print(f"已找到 {hmwk['name']} 于页码 {p}, 第 {hmwkindex} 项")
|
||||
break
|
||||
if not foundhmwk:
|
||||
print(f"!!!!!!未找到 {hmwk['name']}")
|
||||
else:
|
||||
print(f"正在下载 {hmwk['name']} 的 zip 文件")
|
||||
try:
|
||||
message = DownloadZipwithDetail(self.driver,hmwkindex)
|
||||
renamed = RenameRecentzip(self.outputfolder,message)
|
||||
if renamed == 0:
|
||||
downloaded = True
|
||||
self.tableWidget.item(i,1).setBackground(QColor("green"))
|
||||
QApplication.processEvents()
|
||||
except:
|
||||
print(Exception)
|
||||
if not downloaded:
|
||||
print(f"@@@@@@未能下载并改名 {hmwk['name']}")
|
||||
self.tableWidget.item(i,1).setBackground(QColor("red"))
|
||||
i += 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
windows = MyWindow()
|
||||
windows.show()
|
||||
app.exec()
|
||||
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>636</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>下载小闲答题纸</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="pushButton_chrome">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>75</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>chrome路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_driver">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>50</y>
|
||||
<width>75</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>driver路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_outputfolder">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<width>75</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>输出路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_chrome">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>10</y>
|
||||
<width>221</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>此处显示chrome.exe的路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_driver">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>50</y>
|
||||
<width>221</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>此处显示chrome webdriver的路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_outputfolder">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>90</y>
|
||||
<width>221</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>此处显示输出的zip文件的路径</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_openbrowser">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>130</y>
|
||||
<width>71</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>开启浏览器</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_login">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>130</y>
|
||||
<width>71</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>登录</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_exec">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>130</y>
|
||||
<width>201</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>下载答题情况</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>10</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>起始日期</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>50</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>终止日期</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>90</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>年级(regex)</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_startdate">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>10</y>
|
||||
<width>91</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>yyyymmdd</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_enddate">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>50</y>
|
||||
<width>91</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>yyyymmdd</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_graderegex">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>90</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>高[一二]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_getlist">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>130</y>
|
||||
<width>101</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>获取答题卡列表</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>190</y>
|
||||
<width>471</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>答题纸名称</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>已下载</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -49,6 +49,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
|||
self.action_wbzh.triggered.connect(lambda: run_command("文本转换处理",[]))#已完成
|
||||
self.action_hist.triggered.connect(lambda: run_command("生成直方图代码",[]))#已完成
|
||||
self.action_xzth.triggered.connect(lambda: run_command("根据正确率选择题号",[]))#已完成
|
||||
self.action_xzxx.triggered.connect(lambda: run_command("下载小闲答题数据",[]))#已完成
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Reference in New Issue