From 88fab67a9db247f3a635f6ec18d2cfa14a2d3666 Mon Sep 17 00:00:00 2001 From: hubobel Date: Sun, 21 Jun 2026 17:43:25 +0200 Subject: [PATCH] Wartungsupdate --- app.py | 144 ++++++++++++++++++++++++++++++++----- static/style.css | 94 ++++++++++++++++++++++++ templates/maintenance.html | 66 +++++++++++++++++ 3 files changed, 285 insertions(+), 19 deletions(-) diff --git a/app.py b/app.py index 0b814de..3db284b 100644 --- a/app.py +++ b/app.py @@ -212,19 +212,14 @@ def index(): @app.route("/run/balance", methods=["POST"]) def run_balance(): - result = subprocess.run( - [sys.executable, str(BASE_DIR / "balance.py")], - capture_output=True, - text=True + subprocess.run( + [sys.executable, str(BASE_DIR / "balance.py")] ) - return render_template( - "result.html", - title="balance.py", - output=result.stdout + result.stderr + return redirect( + "/maintenance?message=Kontostand erfolgreich aktualisiert" ) - @app.route("/run/transactions", methods=["POST"]) def run_transactions(): @@ -244,11 +239,31 @@ def run_transactions(): capture_output=True, text=True ) + transaction_count = 0 - return render_template( - "result.html", - title="transactions.py", - output=result.stdout + result.stderr + try: + + transactions_file = ( + BASE_DIR + / "Transaktionen" + / str(year) + / "json" + / f"transactions_{year}_KW{int(week):02d}.json" + ) + + if transactions_file.exists(): + with open( + transactions_file, + encoding="utf-8" + ) as f: + transaction_count = len( + json.load(f) + ) + + except Exception: + pass + return redirect( + f"/maintenance?message={transaction_count} Transaktionen geladen" ) @@ -271,11 +286,97 @@ def run_categorize(): capture_output=True, text=True ) + categorized_count = 0 - return render_template( - "result.html", - title="categorize_transactions.py", - output=result.stdout + result.stderr + try: + + categorized_file = ( + BASE_DIR + / "Transaktionen" + / str(year) + / "categorized_json" + / f"categorized_transactions_{year}_KW{int(week):02d}.json" + ) + + if categorized_file.exists(): + with open( + categorized_file, + encoding="utf-8" + ) as f: + categorized_count = len( + json.load(f) + ) + + except Exception: + pass + return redirect( + f"/maintenance?message={categorized_count} Buchungen kategorisiert" + ) +@app.route("/run/weekly_update", methods=["POST"]) +def run_weekly_update(): + + year = request.form.get("year", "").strip() + week = request.form.get("week", "").strip() + + transaction_command = [ + sys.executable, + str(BASE_DIR / "transactions.py") + ] + + categorize_command = [ + sys.executable, + str(BASE_DIR / "categorize_transactions.py") + ] + + if year and week: + + transaction_command.extend( + [year, week] + ) + + categorize_command.extend( + [year, week] + ) + + subprocess.run( + transaction_command + ) + + subprocess.run( + categorize_command + ) + + transaction_count = 0 + + try: + + transactions_file = ( + BASE_DIR + / "Transaktionen" + / str(year) + / "json" + / f"transactions_{year}_KW{int(week):02d}.json" + ) + + if transactions_file.exists(): + with open( + transactions_file, + encoding="utf-8" + ) as f: + transaction_count = len( + json.load(f) + ) + + except Exception: + pass + + message = ( + f"{transaction_count} Transaktionen verarbeitet - " + f"KW {week}/{year}" + ) + + return redirect( + f"/maintenance?message={message}" ) @app.route("/categories") @@ -448,12 +549,17 @@ def maintenance(): year, week, _ = datetime.now().isocalendar() + message = request.args.get( + "message", + "" + ) + return render_template( "maintenance.html", year=year, - week=week + week=week, + message=message ) - @app.route("/log") def show_log(): diff --git a/static/style.css b/static/style.css index 9cdfdd4..f654179 100644 --- a/static/style.css +++ b/static/style.css @@ -289,4 +289,98 @@ text-decoration: underline; .balance-red { color: #c62828; +} +#modal-overlay { + + position: fixed; + + top: 0; + left: 0; + + width: 100%; + height: 100%; + + background: rgba( + 0, + 0, + 0, + 0.5 + ); + + display: flex; + + justify-content: center; + align-items: center; + + z-index: 9999; +} + +#modal { + + background: white; + + padding: 30px; + + border-radius: 12px; + + box-shadow: + 0 0 20px rgba( + 0, + 0, + 0, + 0.3 + ); + + min-width: 400px; + + text-align: center; + +} +#modal p { + + font-size: 18px; + + line-height: 1.5; + + margin-bottom: 20px; +} + +#modal h2 { + + color: #ff6200; + + margin-top: 0; +} + +#modal button { + + margin-top: 20px; + + padding: 10px 25px; + + background: #ff6200; + + color: white; + + border: none; + + border-radius: 6px; + + cursor: pointer; + + font-size: 16px; + + font-weight: bold; +} +#modal button:hover { + + opacity: 0.9; +} +.modal-message { + + font-size: 18px; + + line-height: 1.6; + + margin-bottom: 20px; } \ No newline at end of file diff --git a/templates/maintenance.html b/templates/maintenance.html index 122e68f..3c3c5b1 100644 --- a/templates/maintenance.html +++ b/templates/maintenance.html @@ -56,6 +56,29 @@ +{% if message %} + + + +{% endif %}
@@ -154,7 +177,38 @@
+
+

+ Wochenupdate +

+ +
+ + + + + +

+ Lädt Transaktionen und + kategorisiert automatisch. +

+ + + +
+ +
@@ -167,7 +221,19 @@ Hintergasse © 2026 +