banquepopulaire life insurance investment

This commit is contained in:
Baptiste Delpey 2015-05-18 18:43:40 +02:00 committed by Romain Bignon
commit 886b4bf204
2 changed files with 59 additions and 9 deletions

View file

@ -23,7 +23,8 @@ import urllib
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword, BrokenPageError
from .pages import LoginPage, IndexPage, AccountsPage, AccountsFullPage, CardsPage, TransactionsPage, \
UnavailablePage, RedirectPage, HomePage, Login2Page, InvestmentPage
UnavailablePage, RedirectPage, HomePage, Login2Page, \
LineboursePage, NatixisPage, InvestmentNatixisPage, InvestmentLineboursePage
__all__ = ['BanquePopulaire']
@ -43,6 +44,7 @@ class BanquePopulaire(Browser):
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=ENCOURS_COMPTE.*': CardsPage,
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=SELECTION_ENCOURS_CARTE.*': TransactionsPage,
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=SOLDE.*': TransactionsPage,
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=CONTRAT.*': TransactionsPage,
'https://[^/]+/cyber/internet/Page.do\?.*': TransactionsPage,
'https://[^/]+/cyber/internet/Sort.do\?.*': TransactionsPage,
'https://[^/]+/s3f-web/.*': UnavailablePage,
@ -52,7 +54,10 @@ class BanquePopulaire(Browser):
'https://[^/]+/portailinternet/Pages/default.aspx': HomePage,
'https://[^/]+/portailinternet/Transactionnel/Pages/CyberIntegrationPage.aspx': HomePage,
'https://[^/]+/WebSSO_BP/_(?P<bankid>\d+)/index.html\?transactionID=(?P<transactionID>.*)': Login2Page,
'https://www.linebourse.fr/Portefeuille': InvestmentPage,
'https://www.linebourse.fr/ReroutageSJR': LineboursePage,
'https://www.linebourse.fr/Portefeuille': InvestmentLineboursePage,
'https://www.assurances.natixis.fr/espaceinternet-bp/views/common.*': NatixisPage,
'https://www.assurances.natixis.fr/espaceinternet-bp/views/contrat.*': InvestmentNatixisPage,
}
def __init__(self, website, *args, **kwargs):
@ -181,14 +186,15 @@ class BanquePopulaire(Browser):
def get_investment(self, account):
account = self.get_account(account.id)
params = account._params
if params is None:
return iter([])
params['token'] = self.page.build_token(params['token'])
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(params))
params = self.page.get_investment_page_params()
url, params = self.page.get_investment_page_params()
if params:
self.open('https://www.linebourse.fr/ReroutageSJR', urllib.urlencode(params))
self.location('https://www.linebourse.fr/Portefeuille')
self.location(url, urllib.urlencode(params))
if self.is_on_page(LineboursePage):
self.location('https://www.linebourse.fr/Portefeuille')
elif self.is_on_page(NatixisPage):
self.page.submit_form()
return self.page.get_investments()
return iter([])

View file

@ -413,6 +413,12 @@ class AccountsPage(BasePage):
if m and m.group(1) != 'EQUIPEMENT_COMPLET':
_params['prevAction'] = m.group(1)
next_pages.append(_params)
if not account._params:
account._params = params.copy()
account._params['dialogActionPerformed'] = 'CONTRAT'
account._params['attribute($SEL_$%s)' % tr.attrib['id'].split('_')[0]] = tr.attrib['id'].split('_', 1)[1]
yield account
# Needed to preserve navigation.
@ -631,13 +637,21 @@ class TransactionsPage(BasePage):
def get_investment_page_params(self):
script = self.document.xpath('//body')[0].attrib['onload']
url = None
m = re.search(r"','(.+?)',\[", script, re.MULTILINE)
if m:
url = m.group(1)
params = {}
for key, value in re.findall(r"key:'(?P<key>SJRToken)'\,value:'(?P<value>.*?)'}", script, re.MULTILINE):
params[key] = value
return params
return url, params if url and params else None
class InvestmentPage(_BasePage):
class LineboursePage(_BasePage):
pass
class InvestmentLineboursePage(_BasePage):
COL_LABEL = 0
COL_QUANTITY = 1
COL_UNITVALUE = 2
@ -666,3 +680,33 @@ class InvestmentPage(_BasePage):
if value == '':
return NotAvailable
return Decimal(Transaction.clean_amount(value))
class NatixisPage(_BasePage):
def submit_form(self):
self.browser.select_form(name="formRoutage")
self.browser.submit(nologin=True)
class InvestmentNatixisPage(_BasePage):
COL_LABEL = 0
COL_QUANTITY = 2
COL_UNITVALUE = 3
COL_VALUATION = 4
def get_investments(self):
for line in self.document.xpath('//div[@class="row-fluid table-contrat-supports"]/table/tbody[(@class)]/tr'):
cols = line.findall('td')
inv = Investment()
inv.label = self.parser.tocleanstring(cols[self.COL_LABEL]).replace('Cas sans risque ', '')
inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY])
inv.unitvalue = self.parse_decimal(cols[self.COL_UNITVALUE])
inv.valuation = self.parse_decimal(cols[self.COL_VALUATION])
yield inv
def parse_decimal(self, string):
value = self.parser.tocleanstring(string).replace('Si famille fonds generaux, on affiche un tiret', '').replace('Cas sans risque', '').replace(' ', '')
if value == '-':
return NotAvailable
return Decimal(Transaction.clean_amount(value))