代码拉取完成,页面将自动刷新
def getContext(filepath,code):
contexts = []
f = open(filepath,"r",encoding=code)
lines = f.readlines()
for line in lines:
if line != "\n" and line != "" and line != " \n" and line != "[toc]\n" and line.count("#") != 1:
if "#" in line:
contexts.append("___\n\n#"+line.strip("\n"))
continue
else:
contexts.append(line.strip("\n"))
continue
return contexts
'''1.读取方括号内的内容
2.读取圆括号的内容
3.写入文件'''
path = "D:\\GitbookLibrary\\Discrete-Mathematics-and-Data-Structure\\"
f1 = open(path+"SUMMARY.md","r",encoding = "utf-8")
lines = f1.readlines()
f1.close()
files = []
titles = []
for line in lines:
if "*" in line:
titles.append(line[:line.rfind("]")].replace(" ","#").replace("* [","# "))
files.append(path+line[line.rfind("(")+1:len(line)-2].replace("/","\\"))
continue
f2 = open(path+"summary3.md","w",encoding="utf-8")
n = 0
while n < len(titles):
#while n < 5:
f2.write("___\n"+titles[n]+"\n")
for context in getContext(files[n],"utf-8"):
f2.write(context+"\n")
n += 1
f2.close()
'''
f2 = open(path+"summary3.md","r",encoding="utf-8")
texts = f2.readlines()
f2.close()
outputindexs = []
num = 0
while num +1 < len(texts):
if texts[num] == texts[num+1]:
print(num,texts[num])
outputindexs.append(num+1)
num += 1
continue
else:
outputindexs.append(num)
num += 1
continue'''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。