Kachel Kontostand

This commit is contained in:
hubobel 2026-06-20 18:17:06 +02:00
parent 88c8fac003
commit 47b3fcccc8
3 changed files with 85 additions and 1 deletions

58
app.py
View file

@ -6,12 +6,41 @@ import json
from pathlib import Path
from flask import redirect
from datetime import datetime
from urllib.request import urlopen
from pathlib import Path
app = Flask(__name__)
BASE_DIR = Path(__file__).parent
CATEGORIES_FILE = BASE_DIR / "Kategorien.json"
config = {}
config_file = Path.home() / ".ing.conf"
if not config_file.exists():
config_file = Path(__file__).parent / ".ing.conf"
with open(config_file, encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
if "=" not in line:
continue
key, value = line.split("=", 1)
config[key] = value
IOBROKER_HOST = config["IOBROKER_HOST"]
IOBROKER_PORT = config["IOBROKER_PORT"]
IOBROKER_DP = config["IOBROKER_DP"]
def get_current_week_data():
year, week, _ = datetime.now().isocalendar()
@ -72,7 +101,31 @@ def get_current_week_data():
total_expenses,
total_saldo
)
def get_balance():
try:
url = (
f"http://{IOBROKER_HOST}:{IOBROKER_PORT}"
f"/getPlainValue/{IOBROKER_DP}"
)
value = (
urlopen(url)
.read()
.decode("utf-8")
.strip()
)
return float(value)
except Exception as e:
print(
f"Kontostand konnte nicht gelesen werden: {e}"
)
return None
@app.route("/")
@app.route("/")
def index():
@ -86,6 +139,7 @@ def index():
total_expenses,
total_saldo
) = get_current_week_data()
balance = get_balance()
return render_template(
"index.html",
@ -95,7 +149,9 @@ def index():
transactions=transactions,
total_income=total_income,
total_expenses=total_expenses,
total_saldo=total_saldo
total_saldo=total_saldo,
balance=balance
)
@app.route("/run/balance", methods=["POST"])
def run_balance():

View file

@ -247,4 +247,16 @@ text-decoration: underline;
.transaction-table tr:hover {
background: #f8f8f8;
}
.balance-label {
margin-top: 10px;
margin-bottom: 5px;
color: #666;
}
.balance-value {
font-size: 32px;
font-weight: bold;
color: #ff6200;
margin-top: 0;
}

View file

@ -161,7 +161,23 @@
<h2>
KW{{ week }}
</h2>
<p class="balance-label">
Kontostand
</p>
<p class="balance-value">
{% if balance is not none %}
{{ "%.2f"|format(balance) }} €
{% else %}
n/v
{% endif %}
</p>
<p>
Einnahmen:
<strong>