41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
def cleanup(len_of_prefix, line):
|
|
line = line[line.find(" ")+1:]
|
|
line = line.lower().strip()
|
|
line = line.replace(" ","-")
|
|
line = line.replace("/","")
|
|
return line
|
|
|
|
def add_to_toc(prefix, line):
|
|
link_description = line[line.find(" ")+1:]
|
|
pointer = cleanup(len(prefix), line)
|
|
return prefix + "[" + link_description +"](" + root_path + "#" + pointer + ")"
|
|
|
|
root_path = "https://github.com/Sokow86/awesome-malware-resources/blob/main/README.md"
|
|
f = open("C:\\Users\\%USERNAME%\\Documents\\GitHub\\awesome-malware-resources\\README.md")
|
|
toc = "# Table of Contents\n"
|
|
if(f):
|
|
line = f.readline() # ignore first line
|
|
while True:
|
|
line = f.readline()
|
|
if(line):
|
|
if line.startswith("# Table of Contents"):
|
|
continue
|
|
elif line.startswith("# "):
|
|
prefix = "* "
|
|
elif line.startswith("## "):
|
|
prefix = " * "
|
|
elif line.startswith("### "):
|
|
prefix = " * "
|
|
elif line.startswith("#### "):
|
|
prefix = " * "
|
|
elif line.startswith("##### "):
|
|
prefix = " * "
|
|
elif line.startswith("###### "):
|
|
prefix = " * "
|
|
else:
|
|
continue
|
|
toc = toc + add_to_toc(prefix, line) + "\n"
|
|
else:
|
|
break
|
|
print toc
|