54 lines
2.7 KiB
Python
54 lines
2.7 KiB
Python
lessonpattern = r"G202602[1-2]" # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号
|
|
outputdir = "d:/temp/26届材料" # 输出文件夹, 不建议修改
|
|
answered = True # 设置是否编译答案
|
|
|
|
from database_tools import *
|
|
|
|
# configjson = load_dict("文本文件/config.json")["讲义生成.py"]
|
|
|
|
# lessonpattern = configjson["讲义标题格式"] # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号
|
|
# outputdir = configjson["输出路径"] # 输出文件夹, 不建议修改
|
|
# answered = configjson["提供答案"] # 设置是否编译答案
|
|
|
|
|
|
jsonpath = "../备课组" #有json文件的根目录, 文件名需为"校本材料.json"
|
|
jsondicts = []
|
|
for loc,dirs,files in os.walk(jsonpath):
|
|
if "校本材料.json" in files:
|
|
jsondicts.append(load_dict(os.path.join(loc,"校本材料.json")))
|
|
|
|
|
|
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 notes_dict in jsondicts:
|
|
for lessonid in notes_dict["notes"]:
|
|
if re.findall(lessonpattern,lessonid) != []:
|
|
filename = notes_dict["notes"][lessonid]["id"]+notes_dict["notes"][lessonid]["filename"]+".tex"
|
|
papertype = lessonid[0]
|
|
consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"]
|
|
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") |