bopihive/www.py
2024-12-26 11:46:10 +02:00

44 lines
1.8 KiB
Python

"""
Bopihive
Copyright (C) 2024 fzorb
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import jinja2
import time
from datetime import datetime
import hashlib
import os
environment = jinja2.Environment(loader=jinja2.FileSystemLoader("www/templates/"))
def renderIndex(ct, latest):
with open(f'./archive/{latest}/windows.zip', 'rb') as winFile:
bytes = winFile.read()
sha256Windows = hashlib.sha256(bytes).hexdigest()
sha512Windows = hashlib.sha512(bytes).hexdigest()
md5Windows = hashlib.md5(bytes).hexdigest()
with open(f'./archive/{latest}/linux.zip', 'rb') as linFile:
bytes = linFile.read()
sha256Linux = hashlib.sha256(bytes).hexdigest()
sha512Linux = hashlib.sha512(bytes).hexdigest()
md5Linux = hashlib.md5(bytes).hexdigest()
template = environment.get_template("index.html")
render = template.render(ct=datetime.fromtimestamp(int(ct)), latest=latest, render=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), sha256Linux=sha256Linux, sha256Windows=sha256Windows, sha512Linux=sha512Linux, sha512Windows=sha512Windows, md5Linux=md5Linux, md5Windows=md5Windows)
os.remove("./www/output/index.html")
with open("./www/output/index.html", "x+") as file:
file.write(render)