diff --git a/app.py b/app.py index 08968ca..d197578 100644 --- a/app.py +++ b/app.py @@ -40,6 +40,21 @@ with open(config_file, encoding="utf-8") as f: IOBROKER_HOST = config["IOBROKER_HOST"] IOBROKER_PORT = config["IOBROKER_PORT"] IOBROKER_DP = config["IOBROKER_DP"] +BALANCE_YELLOW_DAY = int( + config["BALANCE_YELLOW_DAY"] +) + +BALANCE_YELLOW_LIMIT = float( + config["BALANCE_YELLOW_LIMIT"] +) + +BALANCE_RED_DAY = int( + config["BALANCE_RED_DAY"] +) + +BALANCE_RED_LIMIT = float( + config["BALANCE_RED_LIMIT"] +) def get_current_week_data(): @@ -126,6 +141,32 @@ def get_balance(): ) return None +from datetime import datetime + + +def get_balance_color(balance): + + if balance is None: + return "green" + + today = datetime.now().day + + if today >= BALANCE_RED_DAY: + + if balance < BALANCE_RED_LIMIT: + return "red" + + if balance < BALANCE_YELLOW_LIMIT: + return "orange" + + return "green" + + if today >= BALANCE_YELLOW_DAY: + + if balance < BALANCE_YELLOW_LIMIT: + return "orange" + + return "green" @app.route("/") def index(): @@ -140,6 +181,7 @@ def index(): total_saldo ) = get_current_week_data() balance = get_balance() + balance_color = get_balance_color(balance) return render_template( "index.html", @@ -150,7 +192,8 @@ def index(): total_income=total_income, total_expenses=total_expenses, total_saldo=total_saldo, - balance=balance + balance=balance, + balance_color = get_balance_color(balance) ) @app.route("/run/balance", methods=["POST"]) diff --git a/static/style.css b/static/style.css index 495e0af..9cdfdd4 100644 --- a/static/style.css +++ b/static/style.css @@ -278,4 +278,15 @@ text-decoration: underline; font-size: 13px; white-space: pre-wrap; +} +.balance-green { + color: #2e7d32; +} + +.balance-orange { + color: #f57c00; +} + +.balance-red { + color: #c62828; } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 0ffbd39..2473cb9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -77,7 +77,7 @@ Kontostand

-

+

{% if balance is not none %}