forked from Z4nzu/hackingtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_readme.py
52 lines (38 loc) · 1.44 KB
/
generate_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# coding=utf-8
import re
from core import HackingTool
from core import HackingToolsCollection
from main import all_tools
def sanitize_anchor(s):
return re.sub(r"\W", "-", s.lower())
def get_toc(tools, indentation = ""):
md = ""
for tool in tools:
if isinstance(tool, HackingToolsCollection):
md += (indentation + "- [{}](#{})\n".format(
tool.TITLE, sanitize_anchor(tool.TITLE)))
md += get_toc(tool.TOOLS, indentation = indentation + ' ')
return md
def get_tools_toc(tools, indentation = "##"):
md = ""
for tool in tools:
if isinstance(tool, HackingToolsCollection):
md += (indentation + "# {}\n".format(tool.TITLE))
md += get_tools_toc(tool.TOOLS, indentation = indentation + '#')
elif isinstance(tool, HackingTool):
if tool.PROJECT_URL:
md += ("- [{}]({})\n".format(tool.TITLE, tool.PROJECT_URL))
else:
md += ("- {}\n".format(tool.TITLE))
return md
def generate_readme():
toc = get_toc(all_tools[:-1])
tools_desc = get_tools_toc(all_tools[:-1])
with open("README_template.md") as fh:
readme_template = fh.read()
readme_template = readme_template.replace("{{toc}}", toc)
readme_template = readme_template.replace("{{tools}}", tools_desc)
with open("README.md", "w") as fh:
fh.write(readme_template)
if __name__ == '__main__':
generate_readme()