Kachel Kontostand
This commit is contained in:
parent
88c8fac003
commit
47b3fcccc8
3 changed files with 85 additions and 1 deletions
58
app.py
58
app.py
|
|
@ -6,12 +6,41 @@ import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from flask import redirect
|
from flask import redirect
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from urllib.request import urlopen
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent
|
BASE_DIR = Path(__file__).parent
|
||||||
CATEGORIES_FILE = BASE_DIR / "Kategorien.json"
|
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():
|
def get_current_week_data():
|
||||||
|
|
||||||
year, week, _ = datetime.now().isocalendar()
|
year, week, _ = datetime.now().isocalendar()
|
||||||
|
|
@ -72,7 +101,31 @@ def get_current_week_data():
|
||||||
total_expenses,
|
total_expenses,
|
||||||
total_saldo
|
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("/")
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|
@ -86,6 +139,7 @@ def index():
|
||||||
total_expenses,
|
total_expenses,
|
||||||
total_saldo
|
total_saldo
|
||||||
) = get_current_week_data()
|
) = get_current_week_data()
|
||||||
|
balance = get_balance()
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
|
|
@ -95,7 +149,9 @@ def index():
|
||||||
transactions=transactions,
|
transactions=transactions,
|
||||||
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
|
||||||
|
|
||||||
)
|
)
|
||||||
@app.route("/run/balance", methods=["POST"])
|
@app.route("/run/balance", methods=["POST"])
|
||||||
def run_balance():
|
def run_balance():
|
||||||
|
|
|
||||||
|
|
@ -247,4 +247,16 @@ text-decoration: underline;
|
||||||
|
|
||||||
.transaction-table tr:hover {
|
.transaction-table tr:hover {
|
||||||
background: #f8f8f8;
|
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;
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +161,23 @@
|
||||||
<h2>
|
<h2>
|
||||||
KW{{ week }}
|
KW{{ week }}
|
||||||
</h2>
|
</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>
|
<p>
|
||||||
Einnahmen:
|
Einnahmen:
|
||||||
<strong>
|
<strong>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue