Commit 7e9b2c2e authored by Simon Rochwerg's avatar Simon Rochwerg Committed by Romain Bignon

[groupama] adds iban scraping

Closes: 6482@zendesk
parent aa1cf84a
......@@ -23,7 +23,7 @@ from weboob.exceptions import BrowserIncorrectPassword
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 @@ class GroupamaBrowser(LoginBrowser):
# 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 @@ class GroupamaBrowser(LoginBrowser):
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
......
......@@ -45,10 +45,10 @@ class GroupamaModule(Module, CapBankWealth):
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)
......
......@@ -110,7 +110,6 @@ class AccountsPage(LoggedPage, HTMLPage):
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 @@ class TransactionsPage(HTMLPage):
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):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment