]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Add a full code example to the docs if a TAN is required (#124)
authorkmille <github@androidloves.me>
Thu, 28 Mar 2024 08:49:00 +0000 (09:49 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Mar 2024 08:49:00 +0000 (09:49 +0100)
* Add a full code example to the docs if a TAN is required

* Improve some minor things

docs/quickstart.rst
docs/tans.rst

index b54ab6ee527ac122098013b796c028a715d0ba2c..2d3788262edae8a9bd1669abea7aabd9c250ee57 100644 (file)
@@ -62,6 +62,6 @@ commands using the client instance:
         # Fetch accounts
         accounts = f.get_sepa_accounts()
 
-Go on to the next pages to find out what commands are supported!
+Go on to the next pages to find out what commands are supported! There is also a full example on how to get your bank transactions if a TAN is required (:ref:`tans-full-example`).
 
 .. _ZKA Website: https://www.hbci-zka.de/register/prod_register.htm
\ No newline at end of file
index 9c3028a9d0b873594e2b58c2c5a67f0ca660e99c..288ceaca67ff540df7b5f742c7b928937479457a 100644 (file)
@@ -181,3 +181,48 @@ Reference
    :inherited-members:
    :member-order: bysource
    :exclude-members: is_unset, naive_parse, print_nested
+
+
+.. _tans-full-example:
+
+Full example
+------------
+
+A full example on how to get transactions if a TAN is required. If a TAN is required ``result`` will be an object of type ``NeedTANResponse``. Otherwise it will hold your transactions directly.
+
+.. code-block:: python
+
+    import datetime
+    from fints.utils import minimal_interactive_cli_bootstrap
+    from fints.client import FinTS3PinTanClient, NeedTANResponse
+    from fints.hhd.flicker import terminal_flicker_unix
+
+    from credentials import blz, username, password, hbci_backend
+
+    client = FinTS3PinTanClient(blz,
+                                username,
+                                password,
+                                hbci_backend)
+    minimal_interactive_cli_bootstrap(client)
+    with client:
+        accounts = client.get_sepa_accounts()
+        for account in accounts:
+            print(f"Doing {account.iban}")
+            result = client.get_transactions(account,
+                                             start_date=datetime.datetime.now() - datetime.timedelta(days=100),
+                                             end_date=datetime.datetime.now())
+            if isinstance(result, NeedTANResponse):
+                print("TAN is required")
+                if getattr(result, 'challenge_hhduc', None):
+                    # Smart-TAN with flicker
+                    try:
+                        terminal_flicker_unix(result.challenge_hhduc)
+                    except KeyboardInterrupt:
+                        pass
+                # else: mobile TAN/manual Smart-TAN/... is used
+                print(result.challenge)
+                tan = input('Please enter TAN:')
+                result = client.send_tan(result, tan)
+            else:
+                print("No TAN is required")
+            print(f"Got {len(result)} transactions for {account.iban}")