diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 366b3843..aeee8e57 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -204,6 +204,21 @@ def spareIDs(dictname): #返回空闲题号 return output #返回的是一个多行的字符串, 每一行中含有一个空闲题号的闭区间 +def NextSpareID(num,adict): #返回adict中下一个空闲的题号 + num = int(num) + while str(num).zfill(6) in adict: + num += 1 + return num + +def NextSpareIDBlock(num,adict): #返回adict中下一个空闲的题号块 + start = NextSpareID(num,adict) + larger_ID_list = [int(id) for id in adict.keys() if int(id)>start] + if larger_ID_list == []: + end = 999999 + else: + end = min(larger_ID_list) - 1 + return str(start)+":"+str(end) + def GenerateProblemListFromString(data): #从来自.tex文件的字符串生成题目列表, 每个item是一道题目, 新一行的%用作前缀 try: data = re.findall(r"\\begin\{document\}([\s\S]*?)\\end\{document\}",data)[0]