[weboob] [PATCH 2/2] Changes to be committed: (use "git reset HEAD <file>..." to unstage)

Nicolas Duhamel nicolas at jombi.fr
Fri Sep 24 18:07:06 CEST 2010


	modified:   weboob/applications/boobank/boobank.py
	modified:   weboob/backends/bp/backend.py
	modified:   weboob/backends/bp/browser.py
	modified:   weboob/capabilities/bank.py

Add a transfer capability and implante it in bp and boobank

Make a transfer in boobank like that:

>transfer fromaccountid toaccoundid amount

Signed-off-by: Nicolas Duhamel <nicolas at jombi.fr>
---
 weboob/applications/boobank/boobank.py |   22 ++++++++++++++++++++++
 weboob/backends/bp/backend.py          |   14 +++++++++++++-
 weboob/backends/bp/browser.py          |   18 ++++++++++++++++++
 weboob/capabilities/bank.py            |    6 ++++++
 4 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py
index 1ffb1bf..09f65ea 100644
--- a/weboob/applications/boobank/boobank.py
+++ b/weboob/applications/boobank/boobank.py
@@ -88,3 +88,25 @@ class Boobank(ReplApplication):
 
         for backend, operation in self.do(do):
             self.format(operation)
+      
+    def do_transfer(self, arg):
+        """
+        Make a transfer beetwen two account
+        """
+        id_from , id_to, amount = arg.split()
+        
+        id_from, backend_name = self.parse_id(id_from)
+        id_to, backend_name = self.parse_id(id_to)
+        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, amount)
+        
+        for backend, operation in self.do(do):
+            pass
+        
+        
+        
+        
+        
diff --git a/weboob/backends/bp/backend.py b/weboob/backends/bp/backend.py
index 6aa9cab..f7f2c0b 100644
--- a/weboob/backends/bp/backend.py
+++ b/weboob/backends/bp/backend.py
@@ -2,7 +2,7 @@
 #
 #	   backend.py
 #	   
-#	   Copyright 2010 nicolas <nicolas at NicolasDesktop>
+#	   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
@@ -52,3 +52,15 @@ class BPBackend(BaseBackend, ICapBank):
 		for history in self.browser.get_history(account):
 			yield history
 	
+	def transfer(self, id_from, id_to, amount):
+		from_account = self.get_account(id_from)
+		to_account = self.get_account(id_to)
+		
+		#TODO: retourner le numero du virement
+		self.browser.make_transfer(from_account, to_account, amount)
+		
+		
+
+
+
+
diff --git a/weboob/backends/bp/browser.py b/weboob/backends/bp/browser.py
index 5b53ab3..9332038 100644
--- a/weboob/backends/bp/browser.py
+++ b/weboob/backends/bp/browser.py
@@ -183,8 +183,26 @@ class BPbrowser(object):
 		
 		
 		
+	def make_transfer(self, from_account, to_account, amount):
+		self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/f_virementSafran.jsp?n=11")
+		self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/aiguillage/saisieComptes.ea")
 		
+		self.Browser.select_form(name="AiguillageForm")
+		self.Browser["idxCompteEmetteur"] = [from_account.id]
+		self.Browser["idxCompteReceveur"] = [to_account.id]
+		self.Browser.submit()
+		
+		self.Browser.select_form(name="VirementNationalForm")
+		self.Browser["montant"] = str(amount)
+		self.Browser.submit()
 		
+		#Confirmation
+		# TODO: verifier que tout c'est bien passe
+		self.Browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
+
+		
+			
+			
 		
 		
 		
diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py
index e08b2f4..91453bb 100644
--- a/weboob/capabilities/bank.py
+++ b/weboob/capabilities/bank.py
@@ -29,6 +29,9 @@ __all__ = ['Account', 'AccountNotFound', 'ICapBank', 'Operation']
 
 class AccountNotFound(Exception):
     pass
+    
+class NotEnoughMoney(Exception):
+    pass
 
 
 class Account(CapBaseObject):
@@ -100,3 +103,6 @@ class ICapBank(IBaseCap):
 
     def iter_history(self, id):
         raise NotImplementedError()
+    
+    def transfer(self, id_from, id_to, amount):
+		raise NotImplementedError()
-- 
1.7.1




More information about the weboob mailing list