59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_新增基础知识梳理 import Ui_Form
|
|
import os
|
|
from database_tools 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):
|
|
bkdatajsonpath = r"../题库0.3/BasicKnowledge.json" # 知识梳理数据库路径
|
|
basicknowledge_dict = load_dict(bkdatajsonpath)
|
|
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(basicknowledge_dict)[1:])+1
|
|
|
|
for line in bkdata:
|
|
if not line.strip() == "":
|
|
id = "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(lesson,obj_list,content)
|
|
basicknowledge_dict[id] = {}
|
|
basicknowledge_dict[id]["lesson"] = lesson
|
|
basicknowledge_dict[id]["objs"] = obj_list
|
|
basicknowledge_dict[id]["content"] = content
|
|
currentid += 1
|
|
|
|
save_dict(basicknowledge_dict,bkdatajsonpath)
|
|
print("已录入完成")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow()
|
|
windows.show()
|
|
app.exec()
|
|
|