Generating report with jinja2

This commit is contained in:
2023-06-12 21:28:03 +02:00
parent 39e83d2336
commit b0d1df83e3
8 changed files with 188 additions and 3 deletions
+20 -1
View File
@@ -1,14 +1,33 @@
#!/usr/bin/env python3
from datetime import datetime
import jinja2
def generateHtmlReport(data):
today = datetime.now().isoformat()[0:10].replace("-", "_")
html = _getHeader()
html += "<body>" \
f"<h1>Reports of {today}</h1>"
dataJinja2 = dict()
dataJinja2['plugins'] = list()
# Env jinja2
env = jinja2.Environment(
loader=jinja2.PackageLoader("reports"),
autoescape=jinja2.select_autoescape()
)
# print(env.list_templates())
tmplIndex = env.get_template("index.html.j2")
body = str()
for plugin in data['system']:
print(plugin)
dataJinja2['plugins'].append(f"{plugin}.html.j2")
dataJinja2['year'] = '2023'
rdr = tmplIndex.render(data=dataJinja2)
# For sysctl
#for entry in data['sysctl']:
# body += f"<h2>Sysctl</h2>"
@@ -34,7 +53,7 @@ def generateHtmlReport(data):
#print(body)
html += "</body></html>"
with open(f"reports/reports_{today}.html", "w") as f:
f.write(html)
f.write(rdr)
def _getHeader() -> str:
header = "<!doctype html>" \