From fc188a8355114c53d74ed1d727e91da4de00c733 Mon Sep 17 00:00:00 2001 From: Fong NGO Date: Fri, 15 Jan 2021 19:33:26 +0100 Subject: [PATCH] [bp] pro website: fix wealth I have managed to find a pro connection with a wealth account (a compte titre). Adapt the code for the new website to fetch investments / history of wealth accounts. Follows the rework of LBP pro website: 97968cde1b646cb05f97ae33489440c5979b9256 --- modules/bp/browser.py | 37 ++++++++++++++++++------------------- modules/bp/pages/pro.py | 3 +-- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/modules/bp/browser.py b/modules/bp/browser.py index abeb25360b..f3c308df7c 100644 --- a/modules/bp/browser.py +++ b/modules/bp/browser.py @@ -712,6 +712,13 @@ def get_history(self, account): return [] + def update_linebourse_session(self): + self.linebourse.session.cookies.update(self.session.cookies) + self.linebourse.session.headers['X-XSRF-TOKEN'] = self.session.cookies.get( + 'XSRF-TOKEN', + domain='labanquepostale.offrebourse.com', + ) + @need_login def go_linebourse(self, account): # Sometimes the redirection done from MarketLoginPage @@ -727,12 +734,7 @@ def go_linebourse(self, account): go = retry(HTTPError, delay=5)(self.market_login.go) go() - self.linebourse.session.cookies.update(self.session.cookies) - self.linebourse.session.headers['X-XSRF-TOKEN'] = self.session.cookies.get( - 'XSRF-TOKEN', - domain='labanquepostale.offrebourse.com', - ) - + self.update_linebourse_session() self.par_accounts_checking.go() def _get_coming_transactions(self, account): @@ -1134,16 +1136,19 @@ def do_login(self): # TODO: implement SCA: requests have changed in comparison to par website def go_linebourse(self, account): - # TODO: update - self.location(account.url) + self.location( + '/ws_q47/voscomptes/bourseenligne/lancementBourseEnLigne-bourseenligne.ea', + params={'numCompte': account.id} + ) # mandatory request (not sure why, not about cookies, maybe to get correct referer) + self.location('../bourseenligne/oicformautopost.jsp') - self.linebourse.session.cookies.update(self.session.cookies) - self.location(self.accounts_url) + self.update_linebourse_session() + + self.pro_accounts_list.go() # just to reinit bprobrowser session to be able to go to linebourse once more @need_login def get_history(self, account): if account.type in (account.TYPE_PEA, account.TYPE_MARKET): - # TODO: NOT TESTED self.go_linebourse(account) return self.linebourse.iter_history(account.id) @@ -1197,15 +1202,9 @@ def get_profile(self): @need_login def iter_investment(self, account): - # TODO: new pro website - # iter_investment of previous pro website uses BPBrowser.iter_investment - # which uses "account.url". The .url attribute doesn't seem useful for pro website, - # try to find connections with wealth accounts to see if we need to use .url attribute - # as it was done before and if we can keep using BPBrowser.iter_investment if account.type == Account.TYPE_MARKET: - # only wealth type is market for pro website (cf. account types in page.pro.py) - # TODO: need to properly type accounts first - raise AssertionError('new pro website: to implement') + self.go_linebourse(account) + return self.linebourse.iter_investments(account.id) return [] @need_login diff --git a/modules/bp/pages/pro.py b/modules/bp/pages/pro.py index 1306fdf17c..370c64d9c9 100644 --- a/modules/bp/pages/pro.py +++ b/modules/bp/pages/pro.py @@ -47,8 +47,7 @@ def is_logged(self): ACCOUNT_TYPES = { - # TODO: add new type names and remove old ones - 'Comptes titres': Account.TYPE_MARKET, # old + 'COMPTE_PLACEMENT': Account.TYPE_MARKET, # seen for a compte titre 'COMPTE_EPARGNE': Account.TYPE_SAVINGS, 'COMPTE_COURANT': Account.TYPE_CHECKING, } -- GitLab