]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Include a CLI utility
authorRaphael Michel <mail@raphaelmichel.de>
Sun, 22 Dec 2019 17:08:51 +0000 (18:08 +0100)
committerRaphael Michel <mail@raphaelmichel.de>
Sun, 22 Dec 2019 17:16:07 +0000 (18:16 +0100)
fints/utils.py

index d7e4d777cf13a8d606cba4de474d8498569aea50..0b0cd08af5926b2e7dac4d50a260ce2ea079fa78 100644 (file)
@@ -297,3 +297,36 @@ class RepresentableEnum(Enum):
 
     def __str__(self):
         return self.value
+
+
+def minimal_interactive_cli_bootstrap(client):
+    """
+    This is something you usually implement yourself to ask your user in a nice, user-friendly way about these things.
+    This is mainly included to keep examples in the documentation simple and allow you to get started quickly.
+    """
+    # Fetch available TAN mechanisms by the bank, if we don't know it already. If the client was created with cached data,
+    # the function is already set.
+    if not client.get_current_tan_mechanism():
+        client.fetch_tan_mechanisms()
+        mechanisms = list(client.get_tan_mechanisms().items())
+        if len(mechanisms) > 1:
+            print("Multiple tan mechanisms available. Which one do you prefer?")
+            for i, m in enumerate(mechanisms):
+                print(i, "Function {p.security_function}: {p.name}".format(p=m[1]))
+            choice = input("Choice: ").strip()
+            client.set_tan_mechanism(mechanisms[int(choice)][0])
+
+    if client.is_tan_media_required() and not client.selected_tan_medium:
+        print("We need the name of the TAN medium, let's fetch them from the bank")
+        with client:
+            m = client.get_tan_media()
+        if len(m[1]) == 1:
+            client.set_tan_medium(m[1][0])
+        else:
+            print("Multiple tan media available. Which one do you prefer?")
+            for i, mm in enumerate(m[1]):
+                print(i,
+                      "Medium {p.tan_medium_name}: Phone no. {p.mobile_number_masked}, Last used {p.last_use}".format(
+                          p=mm))
+            choice = input("Choice: ").strip()
+            client.set_tan_medium(m[1][int(choice)])