新增根据.tex或.pdf生成题号字符串的功能
This commit is contained in:
parent
34b4d8a327
commit
3b61f787a1
|
|
@ -1975,7 +1975,7 @@ def MultiplechoicetoBlankFilling(string_raw): #把多选题的题干和选项转
|
||||||
output = headstring + output[:-2]+"."
|
output = headstring + output[:-2]+"."
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回一个列表, 列表中的每个tuple都是(文件中的题目序号,六位题号)
|
def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回一个列表, 列表中的每个tuple都是(文件中的题目序号(int),六位题号(string))
|
||||||
if filepath[-4:] == ".pdf":
|
if filepath[-4:] == ".pdf":
|
||||||
data = parsePDF(filepath)
|
data = parsePDF(filepath)
|
||||||
idlist = re.findall(r"(\d+)\.[\s\n]*\((\d{6})\)",data)
|
idlist = re.findall(r"(\d+)\.[\s\n]*\((\d{6})\)",data)
|
||||||
|
|
@ -1996,7 +1996,31 @@ def ExtractIDList(filepath): #从文件获取题目序号和ID的对应, 返回
|
||||||
for id in bodylist:
|
for id in bodylist:
|
||||||
ind += 1
|
ind += 1
|
||||||
idlist.append((str(ind),id))
|
idlist.append((str(ind),id))
|
||||||
|
idlist = [(int(id[0]),id[1]) for id in idlist]
|
||||||
return 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__":
|
if __name__ == "__main__":
|
||||||
print("数据库工具, import用.")
|
print("数据库工具, import用.")
|
||||||
Reference in New Issue