From 6bccecd40b7922c86032a39408d6809893738ed7 Mon Sep 17 00:00:00 2001 From: Sokow86 Date: Mon, 29 Mar 2021 10:19:32 +0200 Subject: [PATCH] Add files via upload --- create_toc.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 create_toc.py diff --git a/create_toc.py b/create_toc.py new file mode 100644 index 0000000..85ea0b1 --- /dev/null +++ b/create_toc.py @@ -0,0 +1,40 @@ +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\\ddegroot\\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