[weboob] [PATCH 1/1] Updated transfer command

Matthieu Weber mweber at free.fr
Fri Jan 30 23:14:23 CET 2015


Signed-off-by: Matthieu Weber <mweber at free.fr>
---
 modules/creditmutuel/browser.py |   49 ++++++++++++++++++++++++---------------
 modules/creditmutuel/pages.py   |   20 +++++++++++++++-
 2 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/modules/creditmutuel/browser.py b/modules/creditmutuel/browser.py
index b6b349f..b0ee5c8 100644
--- a/modules/creditmutuel/browser.py
+++ b/modules/creditmutuel/browser.py
@@ -24,6 +24,7 @@ except ImportError:
     from urllib.parse import urlsplit, parse_qsl, urlparse
 
 from datetime import datetime, timedelta
+from random import randint
 
 from weboob.tools.compat import basestring
 from weboob.browser.browsers import LoginBrowser, need_login
@@ -55,7 +56,8 @@ class CreditMutuelBrowser(LoginBrowser):
     card =        URL('/(?P<subbank>.*)/fr/banque/operations_carte.cgi.*',   CardPage)
     noop =        URL('/(?P<subbank>.*)/fr/banque/CR/arrivee.asp.*',         NoOperationsPage)
     info =        URL('/(?P<subbank>.*)/fr/banque/BAD.*',                    EmptyPage)
-    transfert =   URL('/(?P<subbank>.*)/fr/banque/WI_VPLV_VirUniSaiCpt.asp\?(?P<parameters>.*)', TransfertPage)
+    transfert =   URL('/(?P<subbank>.*)/fr/banque/virements/vplw_vi.html',   EmptyPage)
+    transfert_2 = URL('/(?P<subbank>.*)/fr/banque/virements/vplw_cmweb.aspx.*', TransfertPage)
     change_pass = URL('/(?P<subbank>.*)/fr/validation/change_password.cgi',  ChangePasswordPage)
     verify_pass = URL('/(?P<subbank>.*)/fr/validation/verif_code.cgi.*',     VerifCodePage)
     empty =       URL('/(?P<subbank>.*)/fr/$',
@@ -141,23 +143,29 @@ class CreditMutuelBrowser(LoginBrowser):
 
     def transfer(self, account, to, amount, reason=None):
         # access the transfer page
-        parameters = 'RAZ=ALL&Cat=6&PERM=N&CHX=A'
-        page = self.transfert.go(subbank=self.currentSubBank, parameters=parameters)
+        self.transfert.go(subbank=self.currentSubBank)
 
         # fill the form
-        form = self.page.get_form(name='FormVirUniSaiCpt')
-        form['IDB'] = account[-1]
-        form['ICR'] = to[-1]
-        form['MTTVIR'] = '%s' % str(amount).replace('.', ',')
+        form = self.page.get_form(xpath="//form[@id='P:F']")
+        try:
+            form['data_input_indiceCompteADebiter'] = self.page.get_from_account_index(account)
+            form['data_input_indiceCompteACrediter'] = self.page.get_to_account_index(to)
+        except ValueError as e:
+            raise TransferError(e.message)
+        form['[t:dbt%3adouble;]data_input_montant_value_0_'] = '%s' % str(amount).replace('.', ',')
         if reason is not None:
-            form['LIBDBT'] = reason
-            form['LIBCRT'] = reason
-        page = form.submit()
+            form['[t:dbt%3astring;x(27)]data_input_libelleCompteDebite'] = reason
+            form['[t:dbt%3astring;x(31)]data_input_motifCompteCredite'] = reason
+        del form['_FID_GoCancel']
+        del form['_FID_DoValidate']
+        form['_FID_DoValidate.x'] = str(randint(3,125))
+        form['_FID_DoValidate.y'] = str(randint(3,22))
+        form.submit()
 
         # look for known errors
-        content = page.response.text
-        insufficient_amount_message     = u'Montant insuffisant.'
-        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'
+        content = self.page.get_unicode_content()
+        insufficient_amount_message     = u'Le montant du virement doit être positif, veuillez le modifier'
+        maximum_allowed_balance_message = u'Montant maximum autorisé au débit pour ce compte'
 
         if insufficient_amount_message in content:
             raise TransferError('The amount you tried to transfer is too low.')
@@ -166,18 +174,21 @@ class CreditMutuelBrowser(LoginBrowser):
             raise TransferError('The maximum allowed balance for the target account has been / would be reached.')
 
         # look for the known "all right" message
-        ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
-        if ready_for_transfer_message in content:
+        ready_for_transfer_message = u'Confirmer un virement entre vos comptes'
+        if ready_for_transfer_message not in content:
             raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)
 
         # submit the confirmation form
-        form = page.get_form(name='FormVirUniCnf')
+        form = self.page.get_form(xpath="//form[@id='P:F']")
+        del form['_FID_DoConfirm']
+        form['_FID_DoConfirm.x'] =  str(randint(3,125))
+        form['_FID_DoConfirm.y'] =  str(randint(3,22))
         submit_date = datetime.now()
-        page = form.submit()
+        form.submit()
 
         # look for the known "everything went well" message
-        content = page.response.text
-        transfer_ok_message = u'Votre virement a été exécuté ce jour'
+        content = self.page.get_unicode_content()
+        transfer_ok_message = u'Votre virement a été exécuté'
         if transfer_ok_message not in content:
             raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)
 
diff --git a/modules/creditmutuel/pages.py b/modules/creditmutuel/pages.py
index d172e29..f0541b5 100644
--- a/modules/creditmutuel/pages.py
+++ b/modules/creditmutuel/pages.py
@@ -69,7 +69,25 @@ class VerifCodePage(LoggedPage, HTMLPage):
 
 
 class TransfertPage(LoggedPage, HTMLPage):
-    pass
+    def get_account_index(self, direction, account):
+        for div in self.doc.getroot().cssselect(".dw_dli_contents"):
+            inp = div.cssselect("input")[0]
+            if inp.name != direction:
+                continue
+            acct = div.cssselect("span.doux")[0].text.replace(" ","")
+            if account.endswith(acct):
+                return inp.attrib['value']
+        else:
+            raise ValueError("account %s not found" % account)
+
+    def get_from_account_index(self, account):
+        return self.get_account_index('data_input_indiceCompteADebiter', account)
+
+    def get_to_account_index(self, account):
+        return self.get_account_index('data_input_indiceCompteACrediter', account)
+
+    def get_unicode_content(self):
+        return self.content.decode(self.detect_encoding())
 
 
 class AccountsPage(LoggedPage, HTMLPage):
-- 
1.7.10.4




More information about the weboob mailing list