Wartungsupdate

This commit is contained in:
hubobel 2026-06-21 17:43:25 +02:00
parent 7f87ec435c
commit 88fab67a9d
3 changed files with 285 additions and 19 deletions

144
app.py
View file

@ -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():