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