Files
hackingtool/generate_readme.py
Modark 7df27d8383
Some checks failed
lint_python / lint_python (push) Has been cancelled
test_install / test_install (17 0 1 99 99 99) (push) Has been cancelled
test_install / test_install (17 0 2 99 99 99) (push) Has been cancelled
test_install / test_install (17 1 1 ) (push) Has been cancelled
test_install / test_install (99) (push) Has been cancelled
Feat/rich UI menu lovely (#567)
2025-10-14 11:32:18 +05:30

58 lines
1.6 KiB
Python

# coding=utf-8
import re
from rich.console import Console
from rich.theme import Theme
from core import HackingTool
from core import HackingToolsCollection
from hackingtool import all_tools
_theme = Theme({"purple": "#7B61FF"})
console = Console(theme=_theme)
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()