diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index fae59c1f..5c15b0e5 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -2093,5 +2093,26 @@ def makedir(dirpath): #递归创建文件夹 pass return dirlist + +def TitleIDStringtoTupleList(raw_string): #将类json的标题与题号对应变为(标题,题号字符串)的tuple之后组成list + corresponding_list = [] + raw_string = RefinePuctuations(raw_string).replace("{","").replace("}","") + raw_list = [re.sub(r"(?:(?:\s)|(?:,\s*$))","",t) for t in raw_string.split("\n") if not t.strip() == ""] + for raw_item in raw_list: + item = raw_item.replace('"','').replace(";","") + sep = item.find(":") + title = item[:sep] + content = item[sep+1:] + corresponding_list.append((title,content)) + return corresponding_list + +def TitleIDTupleListtoString(correspoinding_list): #将(标题,题号字符串)的tuple组成的list转化为更方便阅读的字符串, 前面有编号 + output_string = "" + count = 0 + for corresp in correspoinding_list: + count += 1 + output_string += f"{count}. {corresp[0]}: {corresp[1]}\n" + return output_string + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file