迁移 新增基础知识梳理

This commit is contained in:
weiye.wang 2024-04-25 22:31:28 +08:00
parent c9f70acdac
commit 96dabd521b
4 changed files with 229 additions and 1 deletions

View File

@ -0,0 +1,60 @@
# -*- 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, QLabel, QLineEdit, QPushButton,
QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(760, 490)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(200, 160, 91, 16))
self.lineEdit_filepath = QLineEdit(Form)
self.lineEdit_filepath.setObjectName(u"lineEdit_filepath")
self.lineEdit_filepath.setGeometry(QRect(200, 180, 381, 20))
self.lineEdit_filepath.setReadOnly(True)
self.pushButton_selectfilepath = QPushButton(Form)
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
self.pushButton_selectfilepath.setGeometry(QRect(494, 150, 91, 24))
self.label_2 = QLabel(Form)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(200, 210, 291, 51))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(500, 210, 81, 51))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u65b0\u589e\u57fa\u7840\u77e5\u8bc6\u68b3\u7406", None))
self.label.setText(QCoreApplication.translate("Form", u"LaTeX\u6587\u4ef6\u4f4d\u7f6e", None))
self.pushButton_selectfilepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6", None))
self.label_2.setText(QCoreApplication.translate("Form", u"LaTeX\u6587\u4ef6\u4e2d\u6709\u4e00\u4e2aenumerate\u73af\u5883.\n"
"\u6bcf\u4e00\u4e2aitem\u540e\u9762\u6709\u4e00\u4e2a\u4e2d\u62ec\u53f7\u5305\u56f4\u7684\u4fe1\u606f, \u4e4b\u540e\u662f\u5185\u5bb9.\n"
"\u4f8b\u5982: \\item [K0101/K0101001B,K0101002B] \u5185\u5bb9", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u57fa\u7840\u77e5\u8bc6", None))
# retranslateUi

View File

@ -15,6 +15,7 @@ from 关键字筛选题号 import MyWindow_sxth
from 添加关联题目 import MyWindow_tjgl
from 批量收录新题 import MyWindow_bdsl
from 下载小闲答题数据 import MyWindow_xxxz
from 新增基础知识梳理 import MyWindow_tjjc
from database_tools_2 import *
class MyWindow(QMainWindow,Ui_MainWindow):
@ -43,6 +44,10 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab
self.layout_tjjc = QVBoxLayout(self.tab_tjjc)
self.tjjc = MyWindow_tjjc(self.database)
self.layout_tjjc.addWidget(self.tjjc) #以上三行为初始化“小闲下载”tab
self.layout_xxxz = QVBoxLayout(self.tab_xxxz)
self.xxxz = MyWindow_xxxz()
self.layout_xxxz.addWidget(self.xxxz) #以上三行为初始化“小闲下载”tab
@ -97,7 +102,8 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.ndsx.setdbname,
self.sxth.setdbname,
self.tjgl.setdbname,
self.bdsl.setdbname
self.bdsl.setdbname,
self.tjjc.setdbname
]: #在列表中的tab里传送数据库名的连接
self.sendDBname.connect(func)
def sendValue(self):

View File

@ -0,0 +1,71 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_新增基础知识梳理 import Ui_Form
import os
from database_tools_2 import *
class MyWindow_tjjc(QWidget,Ui_Form):
def __init__(self,database_name):
super().__init__()
self.database_name = database_name
self.setupUi(self)
self.bind()
def setdbname(self,string):
self.database_name = string
# print(self.database_name)
def bind(self):
self.pushButton_exec.setDisabled(True)
self.pushButton_selectfilepath.clicked.connect(self.selectfilepath)
self.pushButton_exec.clicked.connect(self.exec)
def selectfilepath(self):
self.filepath = QFileDialog.getOpenFileName(self,"选择.tex文件",os.getcwd(),"tex文件(*.tex);;所有文件(*)")[0]
self.lineEdit_filepath.setText(self.filepath)
self.pushButton_exec.setEnabled(True)
def exec(self):
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
mycursor = mydb.cursor()
mycursor.execute("SELECT bn_id FROM basic_knowledges;")
bnids = [ret[0] for ret in mycursor.fetchall()]
bkdata_raw = ReadTextFile(self.filepath)
bkdatabody = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate\}",bkdata_raw)[0].strip().split("\\item")
bkdata = [line.strip() for line in bkdatabody if "[" in line and "]" in line]
currentid = int(max(bnids)[1:])+1
for line in bkdata:
if not line.strip() == "":
bnid = f"B{str(currentid).zfill(5)}"
pos = line.index("]")
head = line[1:pos]
content = line[pos+1:].strip()
lesson,objs = head.split("/")
obj_list = objs.split(",")
print(f"{bnid} {obj_list} {content}")
sql = "INSERT INTO basic_knowledges (bn_id,bn_content) VALUE (%s,%s);"
val = (bnid,content)
mycursor.execute(sql,val)
for objid in obj_list:
sql = "INSERT INTO bn_obj_corresp (bn_id,obj_id) VALUE (%s,%s);"
val = (bnid,objid)
mycursor.execute(sql,val)
sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);"
val = (GetDate(),GetTime(),get_git_username(),"新增基础",f"{bnid} {obj_list} {content}")
mycursor.execute(sql,val)
currentid += 1
mydb.commit()
mydb.close()
print("已录入完成")
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow()
windows.show()
app.exec()

View File

@ -0,0 +1,91 @@
<?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>760</width>
<height>490</height>
</rect>
</property>
<property name="windowTitle">
<string>新增基础知识梳理</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>200</x>
<y>160</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>LaTeX文件位置</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_filepath">
<property name="geometry">
<rect>
<x>200</x>
<y>180</y>
<width>381</width>
<height>20</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButton_selectfilepath">
<property name="geometry">
<rect>
<x>494</x>
<y>150</y>
<width>91</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>选择文件</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>200</x>
<y>210</y>
<width>291</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>LaTeX文件中有一个enumerate环境.
每一个item后面有一个中括号包围的信息, 之后是内容.
例如: \item [K0101/K0101001B,K0101002B] 内容</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>500</x>
<y>210</y>
<width>81</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>添加基础知识</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>