läuft...
This commit is contained in:
commit
477a456b38
2 changed files with 211 additions and 0 deletions
129
README.md
Normal file
129
README.md
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
# ING Kontostandsabfrage für ioBroker
|
||||||
|
|
||||||
|
## Zweck
|
||||||
|
|
||||||
|
Dieses Python-Skript ruft den aktuellen Kontostand eines ING-Kontos per FinTS ab und schreibt den Wert automatisch in einen ioBroker-Datenpunkt über die Simple-API.
|
||||||
|
|
||||||
|
## Systemumgebung
|
||||||
|
|
||||||
|
- Betriebssystem: Debian Linux
|
||||||
|
- Benutzer: `banking`
|
||||||
|
- Ausführungsort: VM `Applikationen`
|
||||||
|
- Bank: ING Deutschland
|
||||||
|
- Übertragung: HTTP Simple-API an ioBroker
|
||||||
|
|
||||||
|
## Verzeichnisstruktur
|
||||||
|
|
||||||
|
```text
|
||||||
|
/home/banking/
|
||||||
|
├── .ing.conf
|
||||||
|
├── bin/
|
||||||
|
│ └── balance.py
|
||||||
|
└── logs/
|
||||||
|
└── balance.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## Konfigurationsdatei
|
||||||
|
|
||||||
|
Datei:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/home/banking/.ing.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Inhalt:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# ING
|
||||||
|
ING_USER=1234567890
|
||||||
|
ING_PIN=geheimepin
|
||||||
|
ING_IBAN=DE00123456789012345678
|
||||||
|
|
||||||
|
# ioBroker
|
||||||
|
IOBROKER_HOST=10.0.1.122
|
||||||
|
IOBROKER_PORT=8087
|
||||||
|
IOBROKER_DP=javascript.0.Finanzen.ING.Kontostand
|
||||||
|
```
|
||||||
|
|
||||||
|
## Berechtigungen
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod 700 /home/banking
|
||||||
|
chmod 700 /home/banking/bin
|
||||||
|
chmod 700 /home/banking/bin/balance.py
|
||||||
|
chmod 700 /home/banking/logs
|
||||||
|
chmod 600 /home/banking/.ing.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Python-Abhängigkeit installieren:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m pip install --user --break-system-packages fints
|
||||||
|
```
|
||||||
|
|
||||||
|
Prüfen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -c "from fints.client import FinTS3PinTanClient; print('OK')"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Manuelle Ausführung
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 /home/banking/bin/balance.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Bei erfolgreicher Ausführung erfolgt keine Konsolenausgabe.
|
||||||
|
|
||||||
|
Der aktuelle Kontostand wird direkt in den konfigurierten ioBroker-Datenpunkt geschrieben.
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
Fehler werden protokolliert in:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/home/banking/logs/balance.log
|
||||||
|
```
|
||||||
|
|
||||||
|
Logdatei anzeigen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -f /home/banking/logs/balance.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cronjob
|
||||||
|
|
||||||
|
Ausführung Montag bis Samstag alle 4 Stunden:
|
||||||
|
|
||||||
|
```cron
|
||||||
|
0 */4 * * 1-6 /usr/bin/python3 /home/banking/bin/balance.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Cronjob bearbeiten:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
Cronjobs anzeigen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crontab -l
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sicherheit
|
||||||
|
|
||||||
|
- Zugangsdaten werden nicht im Skript gespeichert.
|
||||||
|
- Die Konfiguration liegt ausschließlich in `/home/banking/.ing.conf`.
|
||||||
|
- Die Datei ist nur für den Benutzer `banking` lesbar.
|
||||||
|
- Die ING-Zugangsdaten werden nicht auf dem ioBroker-System gespeichert.
|
||||||
|
- Die Kommunikation erfolgt ausschließlich zwischen der VM `Applikationen`, der ING und dem lokalen ioBroker-Server.
|
||||||
|
|
||||||
|
## Hinweise
|
||||||
|
|
||||||
|
- Für die ING wird FinTS verwendet.
|
||||||
|
- FinTS-Server: `https://fints.ing.de/fints/`
|
||||||
|
- Der ioBroker-Datenpunkt sollte vom Typ `number` sein.
|
||||||
|
- Die ING kann aufgrund regulatorischer Vorgaben eine regelmäßige Anmeldung im normalen Online-Banking verlangen.
|
||||||
82
test.py
Normal file
82
test.py
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from urllib.request import urlopen
|
||||||
|
from datetime import datetime
|
||||||
|
from fints.client import FinTS3PinTanClient
|
||||||
|
|
||||||
|
# Konfiguration laden
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
with open(Path.home() / ".ing.conf") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
|
||||||
|
# Leere Zeilen und Kommentare ignorieren
|
||||||
|
if not line or line.startswith("#"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "=" not in line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
key, value = line.split("=", 1)
|
||||||
|
config[key] = value
|
||||||
|
|
||||||
|
# ING
|
||||||
|
USER = config["ING_USER"]
|
||||||
|
PIN = config["ING_PIN"]
|
||||||
|
TARGET_IBAN = config["ING_IBAN"]
|
||||||
|
|
||||||
|
# ioBroker
|
||||||
|
IOBROKER_HOST = config["IOBROKER_HOST"]
|
||||||
|
IOBROKER_PORT = config["IOBROKER_PORT"]
|
||||||
|
IOBROKER_DP = config["IOBROKER_DP"]
|
||||||
|
|
||||||
|
# ING Deutschland
|
||||||
|
BLZ = "50010517"
|
||||||
|
|
||||||
|
LOGFILE = Path.home() / "logs" / "balance.log"
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = FinTS3PinTanClient(
|
||||||
|
BLZ,
|
||||||
|
USER,
|
||||||
|
PIN,
|
||||||
|
"https://fints.ing.de/fints/",
|
||||||
|
product_id="PythonFinTS"
|
||||||
|
)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
for account in client.get_sepa_accounts():
|
||||||
|
|
||||||
|
if account.iban != TARGET_IBAN:
|
||||||
|
continue
|
||||||
|
|
||||||
|
balance = client.get_balance(account)
|
||||||
|
|
||||||
|
# Zahlenwert extrahieren
|
||||||
|
value = float(balance.amount.amount)
|
||||||
|
|
||||||
|
# An ioBroker senden
|
||||||
|
url = (
|
||||||
|
f"http://{IOBROKER_HOST}:{IOBROKER_PORT}"
|
||||||
|
f"/set/{IOBROKER_DP}?value={value}"
|
||||||
|
)
|
||||||
|
|
||||||
|
urlopen(url).read()
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
with open(LOGFILE, "a") as log:
|
||||||
|
log.write(
|
||||||
|
f"{datetime.now():%Y-%m-%d %H:%M:%S} "
|
||||||
|
f"IBAN nicht gefunden: {TARGET_IBAN}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
with open(LOGFILE, "a") as log:
|
||||||
|
log.write(
|
||||||
|
f"{datetime.now():%Y-%m-%d %H:%M:%S} "
|
||||||
|
f"FEHLER: {e}\n"
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue