from flask import Flask, render_template, request, send_file import os,uuid from database_tools_2 import * # outputpath = os.path.join(os.getcwd(),"临时文件") # makedir(outputpath) # 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 = "../备课组" # jsondicts = {} # 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() app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': global pid,configjson,uuiddir,outputpath uuiddir = str(uuid.uuid4()) outputpath = os.path.join(os.getcwd(),f"临时文件/{uuiddir}") makedir(outputpath) pid = request.form['pid'].strip().upper() pid = RefinePunctuations(pid).replace(" ","") version = request.form['version'] if version == "teacher": configjson = {"教师版": True, "字段显示设置": { "题后空间": False, "课时目标": True, "题目标签": True, "答案": True, "解答与提示": True, "使用记录": [-1,-1], "来源": True, "备注": True, "届别": [] }, "编译单个文件": True, "编译合集": False } elif version == "student": configjson = {"教师版": False, "字段显示设置": { "题后空间": True, "课时目标": False, "题目标签": False, "答案": False, "解答与提示": False, "使用记录": [-2,-1], "来源": False, "备注": False, "届别": [] }, "编译单个文件": True, "编译合集": False } elif version == "withanswer": configjson = {"教师版": False, "字段显示设置": { "题后空间": False, "课时目标": False, "题目标签": False, "答案": True, "解答与提示": False, "使用记录": [-2,-1], "来源": False, "备注": False, "届别": [] }, "编译单个文件": True, "编译合集": False } 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 notes_dict: try: 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") consecutivenumbering = structure_dict[papertype]["consecutivenumbering"] texdata = GenerateSingleLessonNotefromMariaDB(mycursor,pid,structure_dict,notes_dict,"./模板文件/讲义模板.txt",os.path.join(outputpath,filename),configjson,consecutivenumbering) #20240415版讲义生成 mydb.close() return f'''