Skip to content

Instantly share code, notes, and snippets.

@Bouni
Created November 22, 2022 09:32
Show Gist options
  • Save Bouni/2326c942fcf6d743e519ee14ecd5f0d8 to your computer and use it in GitHub Desktop.
Save Bouni/2326c942fcf6d743e519ee14ecd5f0d8 to your computer and use it in GitHub Desktop.
FinTS API Usage for Sparkasse Hochrhein
import datetime
import getpass
from fints.client import FinTS3PinTanClient, NeedTANResponse
from fints.hhd.flicker import terminal_flicker_unix
print("Please enter your login (same as online banking)")
login = input("Login: ").strip()
client_args = (
"68452290", # Your bank's BLZ
login, # Your login name
getpass.getpass("PIN :"), # Your banking PIN
"https://banking-bw1.s-fints-pt-bw.de/fints30",
)
f = FinTS3PinTanClient(*client_args)
def ask_for_tan(response):
print("A TAN is required")
print(response.challenge)
if getattr(response, "challenge_hhduc", None):
try:
terminal_flicker_unix(response.challenge_hhduc)
except KeyboardInterrupt:
pass
tan = input("Please enter TAN:")
return f.send_tan(response, tan)
with f:
if f.init_tan_response:
ask_for_tan(f.init_tan_response)
# Konto auswählen, können je nach dem mehrere sein ...
accounts = f.get_sepa_accounts()
account = accounts[0]
# Kontostand abfragen
balance = f.get_balance(account)
while isinstance(balance, NeedTANResponse):
balance = ask_for_tan(balance)
print(f"Kontostand am {balance.date.strftime('%d.%m.%Y')}: {balance.amount}")
# Umsätze der letzten 30 tage abfragen
transactions = f.get_transactions(
account,
datetime.date.today() - datetime.timedelta(days=30),
datetime.date.today(),
)
while isinstance(transactions, NeedTANResponse):
transactions = ask_for_tan(transactions)
for transaction in transactions:
print("=" * 80)
print(f"Datum: {transaction.data.get('date').strftime('%d.%m.%Y')}")
print(f"Sender/Empfänger: {transaction.data.get('applicant_name')}")
print(f"Referenz: {transaction.data.get('additional_position_reference')}")
print(f"Betrag: {transaction.data.get('amount')}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment