diff --git a/modules/banquepopulaire/browser.py b/modules/banquepopulaire/browser.py index 3c461212..ecf1dc18 100644 --- a/modules/banquepopulaire/browser.py +++ b/modules/banquepopulaire/browser.py @@ -23,7 +23,7 @@ import urllib from weboob.deprecated.browser import Browser, BrowserIncorrectPassword, BrokenPageError from .pages import LoginPage, IndexPage, AccountsPage, AccountsFullPage, CardsPage, TransactionsPage, \ - UnavailablePage, RedirectPage, HomePage, Login2Page + UnavailablePage, RedirectPage, HomePage, Login2Page, InvestmentPage __all__ = ['BanquePopulaire'] @@ -52,6 +52,7 @@ class BanquePopulaire(Browser): 'https://[^/]+/portailinternet/Pages/default.aspx': HomePage, 'https://[^/]+/portailinternet/Transactionnel/Pages/CyberIntegrationPage.aspx': HomePage, 'https://[^/]+/WebSSO_BP/_(?P\d+)/index.html\?transactionID=(?P.*)': Login2Page, + 'https://www.linebourse.fr/Portefeuille': InvestmentPage, } def __init__(self, website, *args, **kwargs): @@ -176,3 +177,17 @@ class BanquePopulaire(Browser): return self.location(self.buildurl('/cyber/internet/Page.do', **next_params)) + + def get_investment(self, account): + account = self.get_account(account.id) + params = account._params + if params is None: + return + params['token'] = self.page.build_token(params['token']) + self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(params)) + 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') + return self.page.get_investments() + diff --git a/modules/banquepopulaire/module.py b/modules/banquepopulaire/module.py index 5bcfdcd9..2177348a 100644 --- a/modules/banquepopulaire/module.py +++ b/modules/banquepopulaire/module.py @@ -89,3 +89,7 @@ class BanquePopulaireModule(Module, CapBank): def iter_coming(self, account): with self.browser: return self.browser.get_history(account, coming=True) + + def iter_investment(self, account): + with self.browser: + return self.browser.get_investment(account) diff --git a/modules/banquepopulaire/pages.py b/modules/banquepopulaire/pages.py index c8f64867..52fbfde0 100644 --- a/modules/banquepopulaire/pages.py +++ b/modules/banquepopulaire/pages.py @@ -27,7 +27,7 @@ from mechanize import Cookie, FormNotFoundError from weboob.exceptions import BrowserUnavailable, BrowserIncorrectPassword from weboob.deprecated.browser import Page as _BasePage, BrokenPageError -from weboob.capabilities.bank import Account +from weboob.capabilities.bank import Account, Investment from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.json import json @@ -627,3 +627,39 @@ class TransactionsPage(BasePage): return True return False + + def get_investment_page_params(self): + script = self.document.xpath('//body')[0].attrib['onload'] + params = {} + for key, value in re.findall(r"key:'(?PSJRToken)'\,value:'(?P.*?)'}", script, re.MULTILINE): + params[key] = value + return params + + +class InvestmentPage(_BasePage): + COL_LABEL = 0 + COL_QUANTITY = 1 + COL_UNITVALUE = 2 + COL_VALUATION = 3 + COL_UNITPRICE = 4 + COL_PERF_PERCENT = 5 + COL_PERF = 6 + def get_investments(self): + for line in self.document.xpath('//table[contains(@summary, "Contenu")]/tbody/tr[@class="color4"]'): + cols1 = line.findall('td') + cols2 = line.xpath('./following-sibling::tr')[0].findall('td') + + inv = Investment() + inv.label = self.parser.tocleanstring(cols1[self.COL_LABEL].xpath('.//span')[0]) + inv.code = self.parser.tocleanstring(cols1[self.COL_LABEL].xpath('./a')[0]).split(' ')[-1] + inv.quantity = self.parse_decimal(cols2[self.COL_QUANTITY]) + inv.unitprice = self.parse_decimal(cols2[self.COL_UNITPRICE]) + inv.unitvalue = self.parse_decimal(cols2[self.COL_UNITVALUE]) + inv.valuation = self.parse_decimal(cols2[self.COL_VALUATION]) + inv.diff = self.parse_decimal(cols2[self.COL_PERF]) + + yield inv + + def parse_decimal(self, string): + value = self.parser.tocleanstring(string) + return Decimal(Transaction.clean_amount(value))