From a4fc1f93282b88dc0e5570390a53c49ef25974ed Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 2 Jul 2023 20:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7v2=E4=B8=AD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88=E7=94=9F=E6=88=90=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/参考答案生成.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 工具v2/参考答案生成.py diff --git a/工具v2/参考答案生成.py b/工具v2/参考答案生成.py new file mode 100644 index 00000000..dca63b55 --- /dev/null +++ b/工具v2/参考答案生成.py @@ -0,0 +1,25 @@ +answeringfilepath = r"C:\Users\weiye\Documents\wwy sync\23届" # 要生成答案的路径 +outputfilepath = "临时文件" # 输出文件路径 + +from database_tools import * + + + +texfiles, texpaths = GetValidTexFiles(answeringfilepath) +pro_dict = load_dict("../题库0.3/problems.json") + +for path in texpaths: + pathname = os.path.split(path)[1] + mainbody = "\n\n\\tableofcontents\n\n\\newpage\n\n" + sections = [] + for f in texfiles: + if f.startswith(path) and len(re.findall("答案",ReadTextFile(f)))<10: + sectionname = os.path.split(f)[1].replace("_","-")[:-4] + idlist = re.findall(r"\((\d{6})\)",ReadTextFile(f)) + sections = sections + [GenerateStudentBodyString([",".join(idlist)],[sectionname],pro_dict,consecutivenumbering=True,answered=True,spaceflag=False)] + mainbody += "\n\n\\newpage\n\n".join(sections) + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + latexstr = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(pathname+" 参考答案",mainbody)) + SaveTextFile(latexstr,os.path.join(outputfilepath,pathname+"参考答案.tex")) + print("正在编译 %s 文件"%os.path.join(outputfilepath,pathname+"参考答案.tex")) + XeLaTeXCompile(outputfilepath,pathname+"参考答案.tex") # 在指定目录中生成相应的答案文件 \ No newline at end of file