From 55de13b53b22a9e094b1d85d8c2c746ffeb5f7f4 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Mon, 29 Jun 2015 10:53:21 +0200 Subject: [PATCH] switch to new website and several fixes --- modules/bnporc/module.py | 23 ++++------------------- modules/bnporc/pp/browser.py | 18 ++++++++++-------- modules/bnporc/pp/pages.py | 14 ++++++++------ 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/modules/bnporc/module.py b/modules/bnporc/module.py index 78cbeeef..d0cf2e74 100644 --- a/modules/bnporc/module.py +++ b/modules/bnporc/module.py @@ -50,7 +50,7 @@ class BNPorcModule(Module, CapBank, CapMessages): Value('website', label='Type de compte', default='pp', choices={'pp': 'Particuliers/Professionnels', 'ent': 'Entreprises', - 'pp2': 'Particuliers/Professionnels (nouveau site)'})) + 'ppold': 'Particuliers/Professionnels (ancien site)'})) STORAGE = {'seen': []} # Store the messages *list* for this duration @@ -62,25 +62,10 @@ class BNPorcModule(Module, CapBank, CapMessages): self._threads_age = datetime.utcnow() def create_default_browser(self): - b = {'pp': BNPorc, 'ent': BNPEnterprise, 'pp2': BNPParibasBrowser} + b = {'ppold': BNPorc, 'ent': BNPEnterprise, 'pp': BNPParibasBrowser} self.BROWSER = b[self.config['website'].get()] - #if self.config['rotating_password'].get().isdigit() and len(self.config['rotating_password'].get()) == 6: - # rotating_password = self.config['rotating_password'].get() - #else: - rotating_password = None - if self.config['website'].get() != 'pp': - return self.create_browser(self.config['login'].get(), - self.config['password'].get()) - else: - return self.create_browser(self.config['login'].get(), - self.config['password'].get(), - password_changed_cb=self._password_changed_cb, - rotating_password=rotating_password) - - def _password_changed_cb(self, old, new): - self.config['password'].set(new) - self.config['rotating_password'].set(old) - self.config.save() + return self.create_browser(self.config['login'].get(), + self.config['password'].get()) def iter_accounts(self): for account in self.browser.get_accounts_list(): diff --git a/modules/bnporc/pp/browser.py b/modules/bnporc/pp/browser.py index a6206f48..11839e69 100644 --- a/modules/bnporc/pp/browser.py +++ b/modules/bnporc/pp/browser.py @@ -25,7 +25,7 @@ from weboob.capabilities.base import find_object from weboob.capabilities.bank import AccountNotFound from weboob.tools.json import json -from .pages import LoginPage, AccountsPage, AccountsIBANPage, HistoryPage +from .pages import LoginPage, AccountsPage, AccountsIBANPage, HistoryPage, TransferInitPage __all__ = ['BNPParibasBrowser'] @@ -59,17 +59,18 @@ class JsonBrowserMixin(object): class BNPParibasBrowser(CompatMixin, JsonBrowserMixin, LoginBrowser): - BASEURL_TEMPLATE = r'https://%s.bnpparibas.net/' + BASEURL_TEMPLATE = r'https://%s.bnpparibas/' BASEURL = BASEURL_TEMPLATE % 'mabanque' TIMEOUT = 30.0 - login = URL(r'identification-wspl-pres/identification\?acceptRedirection=true×tamp=(?P)', + login = URL(r'identification-wspl-pres/identification\?acceptRedirection=true×tamp=(?P\d+)', 'SEEA-pa01/devServer/seeaserver', 'https://mabanqueprivee.bnpparibas.net/fr/espace-prive/comptes-et-contrats\?u=%2FSEEA-pa01%2FdevServer%2Fseeaserver', LoginPage) accounts = URL('udc-wspl/rest/getlstcpt', AccountsPage) ibans = URL('rib-wspl/rpc/comptes', AccountsIBANPage) history = URL('rop-wspl/rest/releveOp', HistoryPage) + transfer_init = URL('virement-wspl/rest/initialisationVirement', TransferInitPage) def switch(self, subdomain): self.BASEURL = self.BASEURL_TEMPLATE % subdomain @@ -83,10 +84,11 @@ class BNPParibasBrowser(CompatMixin, JsonBrowserMixin, LoginBrowser): @need_login def get_accounts_list(self): - ibans = self.ibans.go() - self.accounts.go() - assert self.accounts.is_here() - return self.page.iter_accounts(ibans.get_ibans_dict()) + ibans = self.ibans.go().get_ibans_dict() + ibans.update(self.transfer_init.go(data=JSON({'restitutionVF': 1, 'type': 'TOUS'})).get_ibans_dict()) + + self.accounts.go().iter_accounts(ibans) + return self.page.iter_accounts(ibans) @need_login def get_account(self, _id): @@ -95,7 +97,7 @@ class BNPParibasBrowser(CompatMixin, JsonBrowserMixin, LoginBrowser): @need_login def iter_history(self, account, coming=False): self.page = self.history.go(data=JSON({ - "ibanCrypte": account.id, + "ibanCrypte": account._key, "pastOrPending": 1, "triAV": 0, "startDate": None, diff --git a/modules/bnporc/pp/pages.py b/modules/bnporc/pp/pages.py index 780bb68c..45e02a98 100644 --- a/modules/bnporc/pp/pages.py +++ b/modules/bnporc/pp/pages.py @@ -32,9 +32,6 @@ from weboob.tools.json import json from weboob.tools.date import parse_french_date as Date -__all__ = ['LoginPage'] - - def cast(x, typ, default=None): try: return typ(x or default) @@ -139,19 +136,24 @@ class AccountsPage(BNPPage): for f in self.path('data.infoUdc.familleCompte.*'): for a in f.get('compte'): yield Account.from_dict({ - 'id': a.get('key'), + '_key': a.get('key'), 'label': a.get('libellePersoProduit') or a.get('libelleProduit'), 'currency': a.get('devise'), 'type': self.FAMILY_TO_TYPE.get(f.get('idFamilleCompte')) or Account.TYPE_UNKNOWN, 'balance': a.get('soldeDispo'), 'coming': a.get('soldeAVenir'), - 'iban': ibans.get(a.get('key')) or a.get('value') + 'iban': ibans.get(a.get('key')) }) class AccountsIBANPage(BNPPage): def get_ibans_dict(self): - return dict((a.get('ibanCrypte'), a.get('iban')) for a in self.path('listeRib.*.infoCompte')) + return {a['ibanCrypte']: a['iban'] for a in self.path('data.listeRib.*.infoCompte')} + + +class TransferInitPage(BNPPage): + def get_ibans_dict(self): + return {a['ibanCrypte']: a['iban'] for a in self.path('data.infoVirement.listeComptesCrediteur.*')} class Transaction(FrenchTransaction):