From 7e9b2c2eed228c5d3d4c435150093e6db8bafe1a Mon Sep 17 00:00:00 2001 From: Simon Rochwerg Date: Wed, 8 Aug 2018 15:25:32 +0200 Subject: [PATCH] [groupama] adds iban scraping Closes: 6482@zendesk --- modules/groupama/browser.py | 10 ++++++++-- modules/groupama/module.py | 4 ++-- modules/groupama/pages.py | 14 +++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/groupama/browser.py b/modules/groupama/browser.py index af1226f58f..8aeccdcdc7 100644 --- a/modules/groupama/browser.py +++ b/modules/groupama/browser.py @@ -23,7 +23,7 @@ from weboob.capabilities.bank import Account from weboob.capabilities.base import empty -from .pages import LoginPage, AccountsPage, TransactionsPage, AVAccountPage, AVHistoryPage, FormPage +from .pages import LoginPage, AccountsPage, TransactionsPage, AVAccountPage, AVHistoryPage, FormPage, IbanPage __all__ = ['GroupamaBrowser'] @@ -35,6 +35,7 @@ class GroupamaBrowser(LoginBrowser): login = URL('/wps/portal/login', 'https://authentification.(ganassurances|ganpatrimoine|groupama).fr/cas/login', '/wps/portal/inscription', LoginPage) + iban = URL('/wps/myportal/!ut/(.*)/\?paramNumCpt=(.*)', IbanPage) accounts = URL('/wps/myportal/TableauDeBord', AccountsPage) transactions = URL('/wps/myportal/!ut', TransactionsPage) av_account_form = URL('/wps/myportal/assurancevie/', FormPage) @@ -57,7 +58,7 @@ def do_login(self): # And to get history (or other) we need to use the link again but the link works only once. # So we get balance only for iter_account to not use the new link each time. @need_login - def get_accounts_list(self, balance=True): + def get_accounts_list(self, balance=True, need_iban=False): accounts = [] self.accounts.stay_or_go() for account in self.page.get_list(): @@ -69,6 +70,11 @@ def get_accounts_list(self, balance=True): account.balance, account.currency = self.page.get_av_balance() self.accounts.stay_or_go() if account.balance or not balance: + if account.type != Account.TYPE_LIFE_INSURANCE and need_iban: + self.location(account._link) + if self.transactions.is_here(): + self.page.go_iban() + account.iban = self.page.get_iban() accounts.append(account) return accounts diff --git a/modules/groupama/module.py b/modules/groupama/module.py index 97d426e067..08e1d3c2ae 100644 --- a/modules/groupama/module.py +++ b/modules/groupama/module.py @@ -45,10 +45,10 @@ def create_default_browser(self): self.config['password'].get()) def iter_accounts(self): - return self.browser.get_accounts_list() + return self.browser.get_accounts_list(need_iban=True) def get_account(self, _id): - return find_object(self.browser.get_accounts_list(), id=_id, error=AccountNotFound) + return find_object(self.browser.get_accounts_list(need_iban=True), id=_id, error=AccountNotFound) def iter_history(self, account): return self.browser.get_history(account) diff --git a/modules/groupama/pages.py b/modules/groupama/pages.py index 4e4e1353f7..01b5408462 100644 --- a/modules/groupama/pages.py +++ b/modules/groupama/pages.py @@ -110,7 +110,6 @@ def get_list(self): if accounts and accounts[-1].label == account.label and account.type == Account.TYPE_PEA: self.logger.warning('%s seems to be a duplicate of %s, skipping', account, accounts[-1]) continue - accounts.append(account) return accounts @@ -162,6 +161,19 @@ def get_coming_link(self): return None return re.sub('[ \t\r\n]+', '', a.attrib['href']) + def go_iban(self): + js_event = Attr("//a[@class='rib']", 'onclick')(self.doc) + m = re.search("envoyer(.*);", js_event) + iban_params = ast.literal_eval(m.group(1)) + link = iban_params[1] + self.browser.location(link+"?paramNumCpt={}".format(iban_params[0])) + + +class IbanPage(LoggedPage, HTMLPage): + + def get_iban(self): + return CleanText('(//b[contains(text(), "IBAN")])[1]/../text()')(self.doc) + class AVAccountPage(LoggedPage, HTMLPage): """ -- GitLab