diff --git a/.gitignore b/.gitignore index 1c882ef7..7972ffea 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ **/*test* *.sh *static +*.log + diff --git a/工具v4/templates/download.html b/工具v4/templates/download.html new file mode 100644 index 00000000..e69de29b diff --git a/工具v4/templates/get_id.html b/工具v4/templates/get_id.html new file mode 100644 index 00000000..07d36934 --- /dev/null +++ b/工具v4/templates/get_id.html @@ -0,0 +1,17 @@ + + + + 输入ID信息 + + +

请输入试卷ID(如 W20260201 等)或题号序列(如 1:5,7:8,20001 等)

+
+ +

+
+ 仅题目和答案
+
+ +
+ + \ No newline at end of file diff --git a/工具v4/tikuweb.py b/工具v4/tikuweb.py new file mode 100644 index 00000000..f22aa89e --- /dev/null +++ b/工具v4/tikuweb.py @@ -0,0 +1,161 @@ +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,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() + 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, + "课时目标": False, + "题目标签": False, + "答案": True, + "解答与提示": False, + "使用记录": [-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() + if re.findall(r"[A-Za-z]",pid) != []: + if pid in jsondicts: + try: + filename = pid+jsondicts[pid]["filename"].replace("(","").replace(")","")+".tex" + papertype = pid[0] + 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版讲义生成 + mydb.close() + return f''' +

{pid} PDF 文件生成完毕

+ 下载生成的PDF文件 + 下载生成的TEX源文件 + ''' + + except: + mydb.close() + return "出现错误" + else: + mydb.close() + return f"{pid} 未被收录, 请退回重试." + else: + try: + filename = "题号选题.tex" + # 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") + mycursor.execute("SELECT ID FROM problems;") + id_list_in_DB = [ret[0] for ret in mycursor.fetchall()] + problems_list = generate_number_set(pid,id_list_in_DB) + if len(problems_list) <= 100: + bodystring = "\\begin{enumerate}\n\n" + for singleid in problems_list: + bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,singleid,configjson) + "\n" + bodystring += "\\end{enumerate}\n\n" + templatepath = "../工具v3/模板文件/讲义模板.txt" + outputfilepath = os.path.join(outputpath,filename) + texdata = ReadTextFile(templatepath) + texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texdata,("选题编译",bodystring)) + SaveTextFile(texdata,outputfilepath) + XeLaTeXCompile(outputpath,filename) + mydb.close() + return f''' +

{pid} PDF 文件生成完毕

+ 下载生成的PDF文件 + 下载生成的TEX源文件 + ''' + else: + mydb.close() + return f'''

题号列表中的题目数量超过100, 请寻求备课组题库负责同志的帮助

''' + except: + mydb.close() + return "出现错误" + + + return render_template('get_id.html') + +@app.route('/downloadpdf') +def downloadpdf(): + return send_file(os.path.join(outputpath,filename[:-4]+".pdf"), as_attachment=True) + +@app.route('/downloadtex') +def downloadtex(): + return send_file(os.path.join(outputpath,filename), as_attachment=True) + +if __name__ == '__main__': + app.run(host = "0.0.0.0", port = 25432) \ No newline at end of file