新增基础知识梳理 迁移至工具v3 完成

This commit is contained in:
wangweiye7840 2024-04-16 10:51:10 +08:00
parent ce8a8db976
commit f8c77563b8
3 changed files with 217 additions and 0 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(400, 129)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(10, 20, 91, 16))
self.lineEdit_filepath = QLineEdit(Form)
self.lineEdit_filepath.setObjectName(u"lineEdit_filepath")
self.lineEdit_filepath.setGeometry(QRect(10, 40, 381, 20))
self.lineEdit_filepath.setReadOnly(True)
self.pushButton_selectfilepath = QPushButton(Form)
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
self.pushButton_selectfilepath.setGeometry(QRect(304, 10, 91, 24))
self.label_2 = QLabel(Form)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(10, 70, 291, 51))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(310, 70, 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

@ -0,0 +1,66 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_新增基础知识梳理 import Ui_Form
import os
from database_tools_2 import *
class MyWindow(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
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 = "wwylss.synology.me", port = "13306", username="tikuuser", pwd="Kjmathds_2024", db = "tikutest")
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>400</width>
<height>129</height>
</rect>
</property>
<property name="windowTitle">
<string>新增基础知识梳理</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>20</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>10</x>
<y>40</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>304</x>
<y>10</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>10</x>
<y>70</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>310</x>
<y>70</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>