网页获取讲义 适配 材料信息上传值mariadb的情形

This commit is contained in:
weiye.wang 2024-06-16 19:24:59 +08:00
parent d932713f0f
commit 732e3a3fe6
3 changed files with 16 additions and 28 deletions

View File

@ -2534,9 +2534,9 @@ def GenerateSingleLessonTeXfromDict(id,structuredict,notesdict,pro_dict,obj_dict
return rawoutput
def GenerateSingleLessonNotefromMariaDB(cursor,id,structuredict,notesdict,templatepath,outputfilepath,misc,consecutivenumbering = False): #20240415版讲义生成
notetitle = id + r" \ " + notesdict["notes"][id]["name"]
notetitle = id + r" \ " + notesdict[id]["name"]
structure = structuredict[id[0:5].upper()]["structure"]
note_contents = notesdict["notes"][id]
note_contents = notesdict[id]
output = ""
sections_list = []
problems_list = []

View File

@ -79,12 +79,6 @@ class MyWindow_jysc(QWidget,Ui_Form):
def saveandbuild(self):
patterns = self.lineEdit_regex.text().strip().split(",")
# jsonpath = "../备课组" #有json文件的根目录, 文件名需为"校本材料.json"
# jsondicts = []
# for loc,dirs,files in os.walk(jsonpath):
# if "校本材料.json" in files:
# jsondicts.append(load_dict(os.path.join(loc,"校本材料.json")))
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
mycursor = mydb.cursor()
notes_dict = load_notes_dict_from_mariadb(mycursor)

View File

@ -7,7 +7,7 @@ from database_tools_2 import *
# raw_pro_dict = load_dict("../题库0.3/Problems.json")
# obj_dict = load_dict("../题库0.3/LessonObj.json")
# basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json")
jsonpath = "../备课组"
# jsonpath = "../备课组"
# jsondicts = {}
# for loc,dirs,files in os.walk(jsonpath):
# if "校本材料.json" in files:
@ -23,14 +23,7 @@ app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
global pid,configjson,uuiddir,outputpath,jsondicts
jsondicts = {}
os.system("git pull origin master --force")
for loc,dirs,files in os.walk(jsonpath):
if "校本材料.json" in files:
currentdict = load_dict(os.path.join(loc,"校本材料.json"))
for key in currentdict["notes"]:
jsondicts[key] = currentdict["notes"][key].copy()
global pid,configjson,uuiddir,outputpath
uuiddir = str(uuid.uuid4())
outputpath = os.path.join(os.getcwd(),f"临时文件/{uuiddir}")
makedir(outputpath)
@ -41,10 +34,10 @@ def index():
configjson = {"教师版": True,
"字段显示设置": {
"题后空间": False,
"课时目标": False,
"题目标签": False,
"课时目标": True,
"题目标签": True,
"答案": True,
"解答与提示": False,
"解答与提示": True,
"使用记录": [-1,-1],
"来源": True,
"备注": True,
@ -88,18 +81,19 @@ def index():
global filename
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="tikuuser", pwd="Kjmathds_2024", db = "tiku")
mycursor = mydb.cursor()
notes_dict = load_notes_dict_from_mariadb(mycursor)
structure_dict = load_structures_dict_from_mariadb(mycursor)
if re.findall(r"[A-Za-z]",pid) != []:
if pid in jsondicts:
if pid in notes_dict:
try:
filename = pid+jsondicts[pid]["filename"].replace("(","").replace(")","")+".tex"
papertype = pid[0]
grade = pid[3:5]
filename = pid+notes_dict[pid]["filename"].replace("(","").replace(")","")+".tex"
papertype = pid[0:5]
# grade = pid[3:5]
# raw_pro_dict = load_dict("../题库0.3/Problems.json")
# obj_dict = load_dict("../题库0.3/LessonObj.json")
# basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json")
notes_dict = load_dict(f"../备课组/{grade}届/校本材料.json")
consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"]
texdata = GenerateSingleLessonNotefromMariaDB(mycursor,pid,notes_dict,"../工具v3/模板文件/讲义模板.txt",os.path.join(outputpath,filename),configjson,consecutivenumbering) #20240415版讲义生成
consecutivenumbering = structure_dict[papertype]["consecutivenumbering"]
texdata = GenerateSingleLessonNotefromMariaDB(mycursor,pid,structure_dict,notes_dict,"../工具v4/模板文件/讲义模板.txt",os.path.join(outputpath,filename),configjson,consecutivenumbering) #20240415版讲义生成
mydb.close()
return f'''
<h1>{pid} PDF 文件生成完毕</h1>
@ -128,7 +122,7 @@ def index():
for singleid in problems_list:
bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,singleid,configjson) + "\n"
bodystring += "\\end{enumerate}\n\n"
templatepath = "../工具v3/模板文件/讲义模板.txt"
templatepath = "../工具v4/模板文件/讲义模板.txt"
outputfilepath = os.path.join(outputpath,filename)
texdata = ReadTextFile(templatepath)
texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texdata,("选题编译",bodystring))