diff --git a/app.py b/app.py index 8aa29e1..375a282 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ from flask import Flask, render_template, request import subprocess import sys import json -from flask import redirect +from flask import redirect, send_file from urllib.request import urlopen from pathlib import Path from influxdb_client import InfluxDBClient @@ -11,6 +11,7 @@ from datetime import datetime, timedelta from collections import defaultdict from datetime import datetime import shutil +from shutil import copy2 import logging import platform # -------------------------------------------------- @@ -412,6 +413,41 @@ def test_influx(): "last": data[-1] if data else None } +@app.route("/log/download") +def download_log(): + + return send_file( + log_file, + as_attachment=True, + download_name="ing.log" + ) +@app.route("/log/delete") +def delete_log(): + + if log_file.exists(): + + backup_file = ( + log_file.parent + / "ing.log.bak" + ) + + copy2( + log_file, + backup_file + ) + + with open( + log_file, + "w", + encoding="utf-8" + ) as f: + + f.write( + f"{datetime.now()} " + "[INFO] Logdatei gelöscht, Backup erstellt.\n" + ) + + return redirect("/log") @app.route("/run/balance", methods=["POST"]) def run_balance(): diff --git a/static/style.css b/static/style.css index 3e65bfb..652ec0a 100644 --- a/static/style.css +++ b/static/style.css @@ -394,4 +394,37 @@ text-decoration: underline; width: 100% !important; height: 450px !important; +} + + +.log-actions a { + text-decoration: none; +} + +.log-actions button { + min-width: 120px; +} + + +.log-container { + width: 100%; +} + +.log-actions { + display: flex; + justify-content: flex-end; + gap: 12px; + + margin-top: 20px; + margin-bottom: 10px; + + padding-right: 15px; +} + +.log-actions a { + text-decoration: none; +} + +.log-actions button { + min-width: 120px; } \ No newline at end of file diff --git a/templates/log.html b/templates/log.html index 3e4fdb3..24eaf3b 100644 --- a/templates/log.html +++ b/templates/log.html @@ -50,7 +50,22 @@ Log +