import json,re,time



with open("临时文件/problems_edit.tex","r",encoding="u8") as f:
    data = f.read()
problems_string = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate}",data)[0].replace("\\item","<enditem><item>")+"<enditem>"
problems= re.findall("<item>[\s]*\((\d{6})\)([\s\S]*?)<enditem>",problems_string)
editor = re.findall(r"编辑者:[\s]*([^\n]*)",data)[0].strip()

with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
    database = f.read()
pro_dict = json.loads(database)

for item in problems:
    id = item[0]
    content = item[1].strip()
    if pro_dict[id]["content"] == content:
        print("题号%s内容未改变."%id)
    else:
        pro_dict[id]["content"] = content
        pro_dict[id]["edit"].append("%s%s%s\t%s"%(str(time.localtime().tm_year).zfill(4),str(time.localtime().tm_mon).zfill(2),str(time.localtime().tm_mday).zfill(2),editor))

with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
    f.write(json.dumps(pro_dict,indent = 4, ensure_ascii= False))
