[weboob] [PATCH 1/1] Return transfer id Prevent when the two accounts aren't on the same backend

Nicolas Duhamel nicolas at jombi.fr
Tue Sep 28 21:58:54 CEST 2010


Signed-off-by: Nicolas Duhamel <nicolas at jombi.fr>
---
 weboob/applications/boobank/boobank.py |   15 +++++++++++----
 weboob/backends/bp/backend.py          |    8 ++++----
 weboob/backends/bp/browser.py          |   16 ++++++++++++----
 weboob/capabilities/bank.py            |    2 +-
 4 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py
index f06c604..c30888f 100644
--- a/weboob/applications/boobank/boobank.py
+++ b/weboob/applications/boobank/boobank.py
@@ -125,13 +125,20 @@ class Boobank(ReplApplication):
         """
         id_from, id_to, amount = self.parseargs(line, 3, 3)
 
-        id_from, backend_name = self.parse_id(id_from)
-        id_to, backend_name = self.parse_id(id_to)
+        id_from, backend_name_from = self.parse_id(id_from)
+        id_to, backend_name_to = self.parse_id(id_to)
+        
+        if backend_name_from != backend_name_to:
+            print "Transfer between different backend is not implemented"
+            return
+        else:
+            backend_name = backend_name_from
+        
         names = (backend_name,) if backend_name is not None else None
         self.load_backends(ICapBank, names=names)
 
         def do(backend):
             return backend.transfer(id_from, id_to, float(amount))
 
-        for backend, operation in self.do(do):
-            pass
+        for backend, id_transfer in self.do(do):
+            self.format((('Transfer', str(id_transfer)),))
diff --git a/weboob/backends/bp/backend.py b/weboob/backends/bp/backend.py
index 715eda7..6b834e5 100644
--- a/weboob/backends/bp/backend.py
+++ b/weboob/backends/bp/backend.py
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 #
-#       backend.py
+#      backend.py
 #
-#       Copyright 2010 nicolas <nicolas at jombi.fr>
+#      Copyright 2010 nicolas <nicolas at jombi.fr>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ class BPBackend(BaseBackend, ICapBank):
     VERSION = '0.2'
     LICENSE = 'GPLv3'
     DESCRIPTION = u'La banque postale, French bank'
-    CONFIG = {'login':    BaseBackend.ConfigField(description='Account ID'),
+    CONFIG = {'login':  BaseBackend.ConfigField(description='Account ID'),
               'password': BaseBackend.ConfigField(description='Password of account', is_masked=True)
              }
     BROWSER = BPbrowser
@@ -57,4 +57,4 @@ class BPBackend(BaseBackend, ICapBank):
         to_account = self.get_account(id_to)
 
         #TODO: retourner le numero du virement
-        self.browser.make_transfer(from_account, to_account, amount)
+        return self.browser.make_transfer(from_account, to_account, amount)
diff --git a/weboob/backends/bp/browser.py b/weboob/backends/bp/browser.py
index d5ba4c7..1f1a0b4 100644
--- a/weboob/backends/bp/browser.py
+++ b/weboob/backends/bp/browser.py
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 #
-#	 browser.py
+#    browser.py
 #
-#	 Copyright 2010 nicolas <nicolas at NicolasDesktop>
+#    Copyright 2010 nicolas <nicolas at NicolasDesktop>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#	 MA 02110-1301, USA.
+#    MA 02110-1301, USA.
 
 import mechanize
 import hashlib
@@ -197,4 +197,12 @@ class BPbrowser(object):
 
         #Confirmation
         # TODO: verifier que tout c'est bien passe
-        self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
+        rep = self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
+        html = rep.get_data()
+        
+        pattern = "Votre virement N.+ ([0-9]+) "
+        
+        regex = re.compile(pattern)
+        match = regex.search(html)
+        id_transfer = match.groups()[0]
+        return id_transfer
diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py
index 91453bb..430aa10 100644
--- a/weboob/capabilities/bank.py
+++ b/weboob/capabilities/bank.py
@@ -24,7 +24,7 @@ if sys.version_info[:2] <= (2, 5):
 from .base import IBaseCap, CapBaseObject
 
 
-__all__ = ['Account', 'AccountNotFound', 'ICapBank', 'Operation']
+__all__ = ['Account', 'AccountNotFound', 'NotEnoughMoney', 'ICapBank', 'Operation']
 
 
 class AccountNotFound(Exception):
-- 
1.7.1




More information about the weboob mailing list