diff --git a/app.py b/app.py index bdf7223..d47cf47 100644 --- a/app.py +++ b/app.py @@ -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(): diff --git a/static/style.css b/static/style.css index 80962b6..a75fa1b 100644 --- a/static/style.css +++ b/static/style.css @@ -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; } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index a74b25e..4d92a53 100644 --- a/templates/index.html +++ b/templates/index.html @@ -161,7 +161,23 @@
+ Kontostand +
++ + {% if balance is not none %} + + {{ "%.2f"|format(balance) }} € + + {% else %} + + n/v + + {% endif %} + +
Einnahmen: