Aktualisierungen

This commit is contained in:
hubobel 2026-06-06 18:16:43 +02:00
parent b59d275b5f
commit 9179fb268f

View file

@ -2,10 +2,10 @@
from pathlib import Path
from datetime import date, timedelta, datetime
from urllib.request import urlopen
from fints.client import FinTS3PinTanClient
import csv
import json
from urllib.request import urlopen
# --------------------------------------------------
# Konfiguration laden
@ -13,10 +13,8 @@ from urllib.request import urlopen
config = {}
# Zuerst Home-Verzeichnis prüfen
config_file = Path.home() / ".ing.conf"
# Falls nicht vorhanden, Datei neben dem Skript verwenden
if not config_file.exists():
config_file = Path(__file__).parent / ".ing.conf"
@ -40,9 +38,21 @@ with open(config_file, encoding="utf-8") as f:
USER = config["ING_USER"]
PIN = config["ING_PIN"]
TARGET_IBAN = config["ING_IBAN"]
# --------------------------------------------------
# ioBroker-Konfiguration
# --------------------------------------------------
IOBROKER_HOST = config["IOBROKER_HOST"]
IOBROKER_PORT = config["IOBROKER_PORT"]
IOBROKER_DP_TRANSACTIONS = config["IOBROKER_DP_TRANSACTIONS"]
IOBROKER_DP_WEEKSUM = config["IOBROKER_DP_WEEKSUM"]
IOBROKER_DP_WEEKEXPENSES = config["IOBROKER_DP_WEEKEXPENSES"]
# --------------------------------------------------
# Bank
# --------------------------------------------------
BLZ = "50010517"
@ -55,19 +65,18 @@ base_dir = Path.home() / "Transaktionen"
if not base_dir.exists():
base_dir = Path(__file__).parent / "Transaktionen"
# Kalenderwoche bestimmen
year, week, _ = datetime.now().isocalendar()
year_dir = base_dir / str(year)
csv_dir = year_dir / "csv"
json_dir = year_dir / "json"
# Verzeichnisse anlegen
csv_dir.mkdir(parents=True, exist_ok=True)
json_dir.mkdir(parents=True, exist_ok=True)
CSV_FILE = csv_dir / f"transactions_{year}_KW{week:02d}.csv"
JSON_FILE = json_dir / f"transactions_{year}_KW{week:02d}.json"
# --------------------------------------------------
# ING-Verbindung
# --------------------------------------------------
@ -81,6 +90,7 @@ client = FinTS3PinTanClient(
)
export_data = []
transactions = []
# --------------------------------------------------
# Transaktionen abrufen
@ -105,10 +115,11 @@ with client:
for transaction in transactions:
data = transaction.data
amount = data.get("amount")
row = {
"date": str(data.get("date", "")),
"amount": str(data.get("amount", "")),
"amount": round(float(amount.amount), 2) if amount else 0.0,
"posting_text": data.get("posting_text", ""),
"applicant_name": data.get("applicant_name", ""),
"purpose": data.get("purpose", "")
@ -157,7 +168,6 @@ with open(JSON_FILE, "w", encoding="utf-8") as jsonfile:
indent=2
)
# --------------------------------------------------
# Statistiken berechnen
# --------------------------------------------------
@ -168,6 +178,7 @@ week_sum = 0.0
week_expenses = 0.0
for transaction in transactions:
amount = float(transaction.data["amount"].amount)
week_sum += amount
@ -175,6 +186,9 @@ for transaction in transactions:
if amount < 0:
week_expenses += abs(amount)
week_sum = round(week_sum, 2)
week_expenses = round(week_expenses, 2)
# --------------------------------------------------
# An ioBroker senden
# --------------------------------------------------
@ -182,30 +196,26 @@ for transaction in transactions:
base_url = f"http://{IOBROKER_HOST}:{IOBROKER_PORT}/set"
urlopen(
f"{base_url}/javascript.0.Variablen.Konto_Transaktionen"
f"{base_url}/{IOBROKER_DP_TRANSACTIONS}"
f"?value={transaction_count}"
).read()
urlopen(
f"{base_url}/javascript.0.Variablen.Konto_Wochensumme"
f"?value={round(week_sum, 2)}"
f"{base_url}/{IOBROKER_DP_WEEKSUM}"
f"?value={week_sum}"
).read()
urlopen(
f"{base_url}/javascript.0.Variablen.Konto_Wochenausgaben"
f"?value={round(week_expenses, 2)}"
f"{base_url}/{IOBROKER_DP_WEEKEXPENSES}"
f"?value={week_expenses}"
).read()
# --------------------------------------------------
# Erfolgsmeldung
# --------------------------------------------------
transaction_count = len(export_data)
url = (
f"http://{IOBROKER_HOST}:{IOBROKER_PORT}"
f"/set/{IOBROKER_DP_TRANSACTIONS}"
f"?value={transaction_count}"
)
urlopen(url).read()
print(f"CSV erstellt : {CSV_FILE}")
print(f"JSON erstellt: {JSON_FILE}")
print(f"Transaktionen: {transaction_count}")
print(f"Wochensumme : {week_sum:.2f} EUR")
print(f"Ausgaben : {week_expenses:.2f} EUR")