This commit is contained in:
hubobel 2026-06-20 19:57:21 +02:00
parent c69ba3873c
commit 75d20b03a7
3 changed files with 56 additions and 2 deletions

45
app.py
View file

@ -40,6 +40,21 @@ with open(config_file, encoding="utf-8") as f:
IOBROKER_HOST = config["IOBROKER_HOST"] IOBROKER_HOST = config["IOBROKER_HOST"]
IOBROKER_PORT = config["IOBROKER_PORT"] IOBROKER_PORT = config["IOBROKER_PORT"]
IOBROKER_DP = config["IOBROKER_DP"] 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(): def get_current_week_data():
@ -126,6 +141,32 @@ def get_balance():
) )
return None 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("/") @app.route("/")
def index(): def index():
@ -140,6 +181,7 @@ def index():
total_saldo total_saldo
) = get_current_week_data() ) = get_current_week_data()
balance = get_balance() balance = get_balance()
balance_color = get_balance_color(balance)
return render_template( return render_template(
"index.html", "index.html",
@ -150,7 +192,8 @@ def index():
total_income=total_income, total_income=total_income,
total_expenses=total_expenses, total_expenses=total_expenses,
total_saldo=total_saldo, total_saldo=total_saldo,
balance=balance balance=balance,
balance_color = get_balance_color(balance)
) )
@app.route("/run/balance", methods=["POST"]) @app.route("/run/balance", methods=["POST"])

View file

@ -278,4 +278,15 @@ text-decoration: underline;
font-size: 13px; font-size: 13px;
white-space: pre-wrap; white-space: pre-wrap;
}
.balance-green {
color: #2e7d32;
}
.balance-orange {
color: #f57c00;
}
.balance-red {
color: #c62828;
} }

View file

@ -77,7 +77,7 @@
Kontostand Kontostand
</p> </p>
<p class="balance-value"> <p class="balance-value balance-{{ balance_color }}">
{% if balance is not none %} {% if balance is not none %}