From 0eb664031798bd0d8a227cdfc820f85dfccd442d Mon Sep 17 00:00:00 2001 From: hubobel Date: Sat, 6 Jun 2026 16:44:43 +0200 Subject: [PATCH] =?UTF-8?q?holt=20die=20Ums=C3=A4tze=20der=20letzten=207?= =?UTF-8?q?=20Tage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transactions.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 transactions.py diff --git a/transactions.py b/transactions.py new file mode 100644 index 0000000..bae8e99 --- /dev/null +++ b/transactions.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from datetime import date, timedelta +from fints.client import FinTS3PinTanClient +import csv +import json + +# Konfiguration laden +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 + +USER = config["ING_USER"] +PIN = config["ING_PIN"] +TARGET_IBAN = config["ING_IBAN"] + +BLZ = "50010517" + +# Exportverzeichnis bestimmen +export_dir = Path.home() / "logs" + +if not export_dir.exists(): + export_dir = Path(__file__).parent / "logs" + +# Verzeichnis bei Bedarf anlegen +export_dir.mkdir(parents=True, exist_ok=True) + +CSV_FILE = export_dir / "transactions.csv" +JSON_FILE = export_dir / "transactions.json" + +client = FinTS3PinTanClient( + BLZ, + USER, + PIN, + "https://fints.ing.de/fints/", + product_id="PythonFinTS" +) + +export_data = [] + +with client: + for account in client.get_sepa_accounts(): + + if account.iban != TARGET_IBAN: + continue + + transactions = client.get_transactions( + account, + start_date=date.today() - timedelta(days=7), + end_date=date.today() + ) + + for transaction in transactions: + + data = transaction.data + + row = { + "date": str(data.get("date", "")), + "amount": str(data.get("amount", "")), + "posting_text": data.get("posting_text", ""), + "applicant_name": data.get("applicant_name", ""), + "purpose": data.get("purpose", "") + } + + export_data.append(row) + + break + +# CSV schreiben +with open(CSV_FILE, "w", newline="", encoding="utf-8") as csvfile: + writer = csv.DictWriter( + csvfile, + fieldnames=[ + "date", + "amount", + "posting_text", + "applicant_name", + "purpose" + ], + delimiter=";" + ) + + writer.writeheader() + writer.writerows(export_data) + +# JSON schreiben +with open(JSON_FILE, "w", encoding="utf-8") as jsonfile: + json.dump( + export_data, + jsonfile, + ensure_ascii=False, + indent=2 + ) \ No newline at end of file