newbkdatapath = r"C:\Users\wangweiye\Documents\wwy sync\临时工作区\补充知识梳理.tex" # 新增的知识梳理的latex文件路径
bkdatajsonpath = r"../题库0.3/BasicKnowledge.json" # 知识梳理数据库路径

from database_tools import *

basicknowledge_dict = load_dict(bkdatajsonpath)
bkdata_raw = ReadTextFile(newbkdatapath)
bkdatabody = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate\}",bkdata_raw)[0].strip().split("\\item")
bkdata = [line.strip() for line in bkdatabody if "[" in line and "]" in line]


currentid = int(max(basicknowledge_dict)[1:])+1

for line in bkdata:
    if not line.strip() == "":
        id = "B" + str(currentid).zfill(5)
        pos = line.index("]")
        head = line[1:pos]
        content = line[pos+1:].strip()
        lesson,objs = head.split("/")
        obj_list = objs.split(",")
        print(lesson,obj_list,content)
        basicknowledge_dict[id] = {}
        basicknowledge_dict[id]["lesson"] = lesson
        basicknowledge_dict[id]["objs"] = obj_list
        basicknowledge_dict[id]["content"] = content
        currentid += 1

save_dict(basicknowledge_dict,bkdatajsonpath)