handmadeusagedatafilepath = r"临时文件/手动统计结果.txt" #手动统计文件的位置
metadatafilepath = r"文本文件/metadata.txt" #输出的metadata文件的位置


from database_tools import *

raw_data = ReadTextFile(handmadeusagedatafilepath) 
data_list = [d.strip() for d in re.findall(r"\[BEGIN\]([\s\S]*?)\[END\]",raw_data)]
output = "usages\n\n"

for item in data_list:
    lines = item.split("\n")
    for line in lines:
        if line.startswith("##"):
            date = line.replace("##","").strip()
        elif line.startswith("**"):
            classname = line.replace("**","").strip()
        else:
            linedata = re.sub(r"\s+","\t",line)
            usage = linedata.split("\t")
            id = usage.pop(0)
            usagestr = "\t".join(usage)
            output += "%s\n%s\t%s\t%s\n\n"%(id.zfill(6),date,classname,usagestr)

SaveTextFile(output,metadatafilepath)
    
