Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Z4nzu
GitHub Repository: Z4nzu/hackingtool
Path: blob/master/generate_readme.py
1267 views
1
import re
2
3
from core import HackingTool
4
from core import HackingToolsCollection
5
from hackingtool import all_tools
6
7
8
def sanitize_anchor(s):
9
return re.sub(r"\W", "-", s.lower())
10
11
12
def get_toc(tools, indentation = ""):
13
md = ""
14
for tool in tools:
15
if isinstance(tool, HackingToolsCollection):
16
md += (indentation + "- [{}](#{})\n".format(
17
tool.TITLE, sanitize_anchor(tool.TITLE)))
18
md += get_toc(tool.TOOLS, indentation = indentation + ' ')
19
return md
20
21
22
def get_tools_toc(tools, indentation = "##"):
23
md = ""
24
for tool in tools:
25
if isinstance(tool, HackingToolsCollection):
26
md += (indentation + "# {}\n".format(tool.TITLE))
27
md += get_tools_toc(tool.TOOLS, indentation = indentation + '#')
28
elif isinstance(tool, HackingTool):
29
if tool.PROJECT_URL:
30
md += ("- [{}]({})\n".format(tool.TITLE, tool.PROJECT_URL))
31
else:
32
md += ("- {}\n".format(tool.TITLE))
33
return md
34
35
36
def generate_readme():
37
toc = get_toc(all_tools[:-1])
38
tools_desc = get_tools_toc(all_tools[:-1])
39
40
with open("README_template.md") as fh:
41
readme_template = fh.read()
42
43
readme_template = readme_template.replace("{{toc}}", toc)
44
readme_template = readme_template.replace("{{tools}}", tools_desc)
45
46
with open("README.md", "w") as fh:
47
fh.write(readme_template)
48
49
50
if __name__ == '__main__':
51
generate_readme()
52
53