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