From f8c77563b88631bd2aedd2ff81cd597fa117d43f Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Tue, 16 Apr 2024 10:51:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9F=BA=E7=A1=80=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E6=A2=B3=E7=90=86=20=E8=BF=81=E7=A7=BB=E8=87=B3?= =?UTF-8?q?=E5=B7=A5=E5=85=B7v3=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/Ui_新增基础知识梳理.py | 60 +++++++++++++++++++++++ 工具v3/新增基础知识梳理.py | 66 +++++++++++++++++++++++++ 工具v3/新增基础知识梳理.ui | 91 +++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 工具v3/Ui_新增基础知识梳理.py create mode 100644 工具v3/新增基础知识梳理.py create mode 100644 工具v3/新增基础知识梳理.ui diff --git a/工具v3/Ui_新增基础知识梳理.py b/工具v3/Ui_新增基础知识梳理.py new file mode 100644 index 00000000..a54b7be6 --- /dev/null +++ b/工具v3/Ui_新增基础知识梳理.py @@ -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 + diff --git a/工具v3/新增基础知识梳理.py b/工具v3/新增基础知识梳理.py new file mode 100644 index 00000000..bfd58b59 --- /dev/null +++ b/工具v3/新增基础知识梳理.py @@ -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() + diff --git a/工具v3/新增基础知识梳理.ui b/工具v3/新增基础知识梳理.ui new file mode 100644 index 00000000..68cc60fe --- /dev/null +++ b/工具v3/新增基础知识梳理.ui @@ -0,0 +1,91 @@ + + + Form + + + + 0 + 0 + 400 + 129 + + + + 新增基础知识梳理 + + + + + 10 + 20 + 91 + 16 + + + + LaTeX文件位置 + + + + + + 10 + 40 + 381 + 20 + + + + true + + + + + + 304 + 10 + 91 + 24 + + + + 选择文件 + + + + + + 10 + 70 + 291 + 51 + + + + LaTeX文件中有一个enumerate环境. +每一个item后面有一个中括号包围的信息, 之后是内容. +例如: \item [K0101/K0101001B,K0101002B] 内容 + + + + + + 310 + 70 + 81 + 51 + + + + + true + + + + 添加基础知识 + + + + + +