tikuweb迁移中, 有bug

This commit is contained in:
wwyatKJMATH 2024-05-14 13:16:42 +08:00
parent 47e5a19662
commit cbabafb408
4 changed files with 180 additions and 0 deletions

2
.gitignore vendored
View File

@ -12,3 +12,5 @@
**/*test*
*.sh
*static
*.log

View File

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>输入ID信息</title>
</head>
<body>
<h1>请输入试卷ID(如 W20260201 等)或题号序列(如 1:5,7:8,20001 等)</h1>
<form method="POST">
<label for="name">ID:</label>
<input type="text" id="pid" name="pid"><br><br>
<label><input type="radio" name="version" value="teacher"> 教师版</label><br>
<lable><input type="radio" name="version" value="withanswer"> 仅题目和答案</lable><br>
<label><input type="radio" name="version" value="student"> 学生版</label><br>
<button type="submit">提交</button>
</form>
</body>
</html>

161
工具v4/tikuweb.py Normal file
View File

@ -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'''
<h1>{pid} PDF 文件生成完毕</h1>
<a href="/downloadpdf">下载生成的PDF文件</a>
<a href="/downloadtex">下载生成的TEX源文件</a>
'''
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'''
<h1>{pid} PDF 文件生成完毕</h1>
<a href="/downloadpdf">下载生成的PDF文件</a>
<a href="/downloadtex">下载生成的TEX源文件</a>
'''
else:
mydb.close()
return f'''<h1>题号列表中的题目数量超过100, 请寻求备课组题库负责同志的帮助</h1>'''
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)