This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v2/讲义生成.py

38 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

notes_dict_path = "../备课组/26届/校本材料.json" # 讲义基础知识目标号码所在json数据库路径
lessonpattern = r"G202602((4[0-8])|(53))" # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号
outputdir = "d:/temp/26届材料" # 输出文件夹, 不建议修改
answered = True # 设置是否编译答案
consecutivenumbering = False # 设置是否用连续编号, 试卷请设为True, 普通讲义请设为False
from database_tools import *
notes_dict = load_dict(notes_dict_path)
pro_dict = load_dict("../题库0.3/problems.json")
obj_dict = load_dict("../题库0.3/LessonObj.json")
basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json")
dictionaries = {}
for t in (obj_dict,basicknowledge_dict,pro_dict):
dictionaries.update(t)
papernames = []
multitexdata = []
for lessonid in notes_dict["notes"]:
if re.findall(lessonpattern,lessonid) != []:
filename = notes_dict["notes"][lessonid]["id"]+notes_dict["notes"][lessonid]["filename"]+".tex"
texdata = GenerateSingleLessonNote(id = lessonid,notesdict = notes_dict, metadict = dictionaries, templatepath = ".\模板文件\讲义模板.txt", outputfilepath = os.path.join(outputdir,filename),consecutivenumbering=consecutivenumbering,answered=answered)
papernames.append(notes_dict["notes"][lessonid]["id"]+" \\ "+notes_dict["notes"][lessonid]["name"])
multitexdata.append(re.findall(r"\\begin{center}\n{\\bf\\large \\papername}\n\\end{center}([\s\S]*\\end\{enumerate\})",texdata)[0])
merged = ""
for i in range(len(papernames)):
merged += "\n\n\\chapter{"+papernames[i]+"}\n\n\n"
merged += multitexdata[i]
mergedtext = StringSubstitute(r"<<待替换[\d]+>>",ReadTextFile("./模板文件/合集模板.txt"),[merged])
SaveTextFile(mergedtext,os.path.join(outputdir,f"合集{GetDate()}.tex"))
tocompile = input("需要编译合集吗?(Y/[N]):")
if tocompile[0].upper() == "Y":
XeLaTeXCompile(outputdir,f"合集{GetDate()}.tex")