[weboob] [RFC PATCH v2 2/2] boobank: Add command to download statements

Benjamin Cama benoar at dolka.fr
Tue Apr 2 23:12:32 CEST 2019


Add a specific formatter to display the statement raw.

Signed-off-by: Benjamin <benoar at dolka.fr>
---
Changes in v2:
  - Handle empty statements
---
 weboob/applications/boobank/boobank.py        | 20 +++++++++++++++++++
 .../application/formatters/iformatter.py      |  5 +++++
 weboob/tools/application/formatters/load.py   |  5 ++++-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py
index da0be636f..0ec521ea7 100644
--- a/weboob/applications/boobank/boobank.py
+++ b/weboob/applications/boobank/boobank.py
@@ -459,6 +459,7 @@ class Boobank(CaptchaMixin, ReplApplication):
                            'coming':      'ops_list',
                            'investment':  'investment_list',
                            'advisor':     'advisor_list',
+                           'download_statement':    'raw',
                            }
     COLLECTION_OBJECTS = (Account, Transaction, )
 
@@ -846,6 +847,25 @@ class Boobank(CaptchaMixin, ReplApplication):
             client.request('users/me/accounts/%s' % account_id, data={'balance': account.balance})
             print('- %s (%s%s): %s new transactions' % (account.label, account.balance, account.currency_text, len(r)))
 
+    def do_download_statement(self, line):
+        """
+        download_statement ID
+
+        Download an OFX statement for account ID.
+        """
+        id = self.parse_command_args(line, 1, 1)[0]
+
+        account = self.get_object(id, 'get_account', [])
+        if not account:
+            print('Error: account "%s" not found (Hint: try the command "list")' % id, file=self.stderr)
+            return 2
+
+        statement = self.do('download_statement', account)
+        try:
+            self.format({'statement': next(iter(statement)).decode('utf-8')})
+        except StopIteration:
+            return
+
     def do_advisor(self, line):
         """
         advisor
diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py
index b44ea1d54..567b1533c 100644
--- a/weboob/tools/application/formatters/iformatter.py
+++ b/weboob/tools/application/formatters/iformatter.py
@@ -272,6 +272,11 @@ class PrettyFormatter(IFormatter):
     def get_description(self, obj):
         return None
 
+class RawFormatter(IFormatter):
+    """Display raw values passed"""
+    def format_dict(self, obj):
+        self.output(next(iter(obj.values())))
+
 
 def formatter_test_output(Formatter, obj):
     """
diff --git a/weboob/tools/application/formatters/load.py b/weboob/tools/application/formatters/load.py
index b043c76ce..7ee3d290a 100644
--- a/weboob/tools/application/formatters/load.py
+++ b/weboob/tools/application/formatters/load.py
@@ -26,7 +26,7 @@ class FormatterLoadError(Exception):
 
 
 class FormattersLoader(object):
-    BUILTINS = ['htmltable', 'multiline', 'simple', 'table', 'csv', 'webkit', 'json', 'json_line']
+    BUILTINS = ['htmltable', 'multiline', 'simple', 'table', 'csv', 'webkit', 'json', 'json_line', 'raw']
 
     def __init__(self):
         self.formatters = {}
@@ -77,3 +77,6 @@ class FormattersLoader(object):
         elif name == 'json_line':
             from .json import JsonLineFormatter
             return JsonLineFormatter
+        elif name == 'raw':
+            from .iformatter import RawFormatter
+            return RawFormatter
-- 
2.20.1




More information about the weboob mailing list