From 3b61f787a1221093274e6b67c37bb3c699af945c Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Tue, 13 Feb 2024 10:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=B9=E6=8D=AE.tex?= =?UTF-8?q?=E6=88=96.pdf=E7=94=9F=E6=88=90=E9=A2=98=E5=8F=B7=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 26d62482..0539a7dd 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1975,7 +1975,7 @@ def MultiplechoicetoBlankFilling(string_raw): #把多选题的题干和选项转 output = headstring + output[:-2]+"." return output -def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回一个列表, 列表中的每个tuple都是(文件中的题目序号,六位题号) +def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回一个列表, 列表中的每个tuple都是(文件中的题目序号(int),六位题号(string)) if filepath[-4:] == ".pdf": data = parsePDF(filepath) idlist = re.findall(r"(\d+)\.[\s\n]*\((\d{6})\)",data) @@ -1996,7 +1996,31 @@ def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回 for id in bodylist: ind += 1 idlist.append((str(ind),id)) + idlist = [(int(id[0]),id[1]) for id in idlist] return idlist +def ExportIDList(filepath): #从.tex或.pdf文件获取题目序号和ID的对应(每一行每个题号分别对应第1,2,3...题, 空缺的题号的ID用999999表示), 返回题号字符串 + idlist = ExtractIDList(filepath) + output = "" + currentoutput = [] + for i in range(len(idlist)): + item = idlist[i] + if i == 0: + currentind = item[0] + currentoutput +=["999999"]*(item[0]-1) + currentoutput.append(item[1]) + elif item[0] >= currentind + 1: + currentoutput+=(["999999"]*(item[0]-currentind-1)) + currentind = item[0] + currentoutput.append(item[1]) + else: + output += ",".join(currentoutput)+"\n\n" + currentoutput = [] + currentind = item[0] + currentoutput +=["999999"]*(item[0]-1) + currentoutput.append(item[1]) + output += ",".join(currentoutput)+"\n\n" + return output + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file