From 2f4fa790270eee1db473d0038aaa54125b3e1894 Mon Sep 17 00:00:00 2001
From: hubobel
Date: Tue, 23 Jun 2026 17:49:52 +0200
Subject: [PATCH] =?UTF-8?q?Graph=20hinzugef=C3=BCgt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.py | 67 +++++++++++++++++++++++++++++++++++++++-----
templates/index.html | 53 +++++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+), 7 deletions(-)
diff --git a/app.py b/app.py
index 3db284b..01b5553 100644
--- a/app.py
+++ b/app.py
@@ -1,13 +1,15 @@
-from pathlib import Path
+
from flask import Flask, render_template, request
import subprocess
import sys
import json
-from pathlib import Path
+
from flask import redirect
-from datetime import datetime
+
from urllib.request import urlopen
from pathlib import Path
+from influxdb_client import InfluxDBClient
+from datetime import datetime, timedelta
app = Flask(__name__)
@@ -40,6 +42,10 @@ with open(config_file, encoding="utf-8") as f:
IOBROKER_HOST = config["IOBROKER_HOST"]
IOBROKER_PORT = config["IOBROKER_PORT"]
IOBROKER_DP = config["IOBROKER_DP"]
+INFLUX_URL = config["INFLUX_URL"]
+INFLUX_ORG = config["INFLUX_ORG"]
+INFLUX_BUCKET = config["INFLUX_BUCKET"]
+INFLUX_TOKEN = config["INFLUX_TOKEN"]
BALANCE_YELLOW_DAY = int(
config["BALANCE_YELLOW_DAY"]
)
@@ -178,8 +184,37 @@ def get_balance_color(balance):
return "orange"
return "green"
-@app.route("/")
+
+def get_balance_history(days=30):
+
+ client = InfluxDBClient(
+ url=INFLUX_URL,
+ token=INFLUX_TOKEN,
+ org=INFLUX_ORG
+ )
+
+ query = f'''
+ from(bucket: "{INFLUX_BUCKET}")
+ |> range(start: -{days}d)
+ |> filter(fn: (r) => r._measurement == "Kontostand")
+ |> filter(fn: (r) => r._field == "value")
+ '''
+
+ result = client.query_api().query(query)
+
+ history = []
+
+ for table in result:
+ for record in table.records:
+
+ history.append({
+ "date": record.get_time().strftime("%d.%m"),
+ "value": round(record.get_value(), 2)
+ })
+
+ return history
+@app.route("/")
def index():
(
@@ -192,8 +227,14 @@ def index():
total_expenses,
total_saldo
) = get_current_week_data()
+
balance = get_balance()
- balance_color = get_balance_color(balance)
+
+ balance_color = get_balance_color(
+ balance
+ )
+
+ balance_history = get_balance_history()
return render_template(
"index.html",
@@ -206,9 +247,21 @@ def index():
total_expenses=total_expenses,
total_saldo=total_saldo,
balance=balance,
- balance_color = get_balance_color(balance)
-
+ balance_color=balance_color,
+ balance_history=balance_history
)
+@app.route("/test-influx")
+def test_influx():
+
+ data = get_balance_history()
+
+ return {
+ "count": len(data),
+ "first": data[0] if data else None,
+ "last": data[-1] if data else None
+ }
+
+
@app.route("/run/balance", methods=["POST"])
def run_balance():
diff --git a/templates/index.html b/templates/index.html
index 57d71e0..dfcc47d 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -15,6 +15,8 @@
href="{{ url_for('static', filename='style.css') }}">
+
+
@@ -112,7 +114,15 @@
+
+
+ Kontostand letzte 30 Tage
+
+
+
+
+
@@ -242,6 +252,49 @@ Hintergasse © 2026
+
+
+