diff --git a/modules/wiseed/browser.py b/modules/wiseed/browser.py index 6852303fda377db6d9dbd53b5c29778e88e0c854..30b9ecaf5a92e9ad20b5c9ad2cbc50a9ad2ef281 100644 --- a/modules/wiseed/browser.py +++ b/modules/wiseed/browser.py @@ -22,7 +22,10 @@ from woob.browser import LoginBrowser, need_login, URL, StatesMixin from woob.capabilities.bank import Account -from .pages import LoginPage, LandPage, InvestPage +from .pages import ( + LoginPage, LandPage, InvestPage, StocksPage, BondsPage, + EquitiesPage, +) # TODO implement documents and profile @@ -31,9 +34,12 @@ class WiseedBrowser(LoginBrowser, StatesMixin): BASEURL = 'https://www.wiseed.com' TIMEOUT = 120 - login = URL('/fr/connexion', LoginPage) - landing = URL('/fr/projets-en-financement', LandPage) - invests = URL('/fr/compte/portefeuille', InvestPage) + login = URL(r'/fr/connexion', LoginPage) + landing = URL(r'/fr/projets-en-financement', LandPage) + invests = URL(r'/fr/compte/portefeuille$', InvestPage) + stocks = URL(r'/fr/compte/portefeuille/actions', StocksPage) + bonds = URL(r'/fr/compte/portefeuille/obligations', BondsPage) + equities = URL(r'/fr/compte/portefeuille/titres-participatifs', EquitiesPage) def do_login(self): self.login.go() @@ -65,11 +71,17 @@ def iter_investment(self): yield self.page.get_liquidities() - for inv in self.page.iter_funded_bond(): + for inv in self.page.iter_funding(): yield inv - for inv in self.page.iter_funded_stock(): + self.bonds.go() + for inv in self.page.iter_funded_bonds(): yield inv - for inv in self.page.iter_funding(): + self.stocks.go() + for inv in self.page.iter_funded_stocks(): + yield inv + + self.equities.go() + for inv in self.page.iter_funded_equities(): yield inv diff --git a/modules/wiseed/pages.py b/modules/wiseed/pages.py index 5e13608b4a7130856c74069d3f7f36c0533543fa..6e13e752c2dca82cec207bdc1c089663465bd292 100644 --- a/modules/wiseed/pages.py +++ b/modules/wiseed/pages.py @@ -67,66 +67,79 @@ def get_liquidities(self): return create_french_liquidity(value) @method - class iter_funded_stock(TableElement): - item_xpath = '//table[@id="portefeuilleAction"]/tbody/tr' + class iter_funding(TableElement): + def find_elements(self): + for el in self.page.doc.xpath('//div[has-class("panel")]'): + if 'souscription(s) en cours' in CleanText('.')(el): + for sub in el.xpath('.//table[has-class("portefeuille-liste") and not(@id)]/tbody/tr'): + yield sub + return - head_xpath = '//table[@id="portefeuilleAction"]/thead//th' - col_bought = 'Vous avez investi' - col_label = 'Investissement dans' - col_valuation = 'Valeur estimée à date' - col_diff_ratio = 'Coef. de performance intermediaire' + head_xpath = '//table[has-class("portefeuille-liste") and not(@id)]/thead//th' + col_label = 'Opération / Cible' + col_details = 'Détails' class item(ItemElement): klass = Investment obj_label = CleanText(TableCell('label')) - # text is "0000000000000100 100,00 €", wtf - obj_valuation = CleanDecimal.SI( - Regexp(CleanText(TableCell('valuation')), r'^000(\d+)\b') + # Can be "100,00 € + Frais de 0,90 €" or "€100.00" + obj_valuation = Coalesce( + CleanDecimal.French(Regexp(CleanText(TableCell('details')), r'^(.*?) €', default=None), default=None), + CleanDecimal.US(Regexp(CleanText(TableCell('details')), r'^€([^ ]+)', default=None), default=None), ) + +class FundItemElement(ItemElement): + klass = Investment + + obj_label = CleanText(TableCell('label')) + + # text is "0000000000000100 100,00 €" + obj_valuation = CleanDecimal.SI( + Regexp(CleanText(TableCell('bought')), r'^000(\d+)\b') + ) + + +class StocksPage(LoggedPage, HTMLPage): + @method + class iter_funded_stocks(TableElement): + item_xpath = '//table[@id="table-portefeuille-actions"]/tbody/tr' + head_xpath = '//table[@id="table-portefeuille-actions"]/thead//th' + + col_bought = 'Vous avez investi' + col_label = 'Investissement dans' + col_valuation = 'Valeur estimée à date' + col_diff_ratio = 'Coef. de performance intermediaire' + + class item(FundItemElement): obj_diff_ratio = CleanDecimal.SI( Regexp(CleanText(TableCell('diff_ratio')), r'^000(\d+)\b') ) + +class BondsPage(LoggedPage, HTMLPage): @method - class iter_funded_bond(TableElement): - item_xpath = '//div[@id="panel-OBLIGATIONS"]//table[has-class("portefeuille-liste")]/tbody/tr' + class iter_funded_bonds(TableElement): + item_xpath = '//table[@id="table-portefeuille-obligations"]/tbody/tr' + head_xpath = '//table[@id="table-portefeuille-obligations"]/thead//th' - head_xpath = '//div[@id="panel-OBLIGATIONS"]//table[has-class("portefeuille-liste")]/thead//th' col_bought = 'Vous avez investi' col_label = 'Investissement dans' - class item(ItemElement): - klass = Investment - - obj_label = CleanText(TableCell('label')) + class item(FundItemElement): + pass - obj_valuation = CleanDecimal.SI( - Regexp(CleanText(TableCell('bought')), r'^000(\d+)\b') - ) +class EquitiesPage(LoggedPage, HTMLPage): @method - class iter_funding(TableElement): - def find_elements(self): - for el in self.page.doc.xpath('//div[has-class("panel")]'): - if 'souscription(s) en cours' in CleanText('.')(el): - for sub in el.xpath('.//table[has-class("portefeuille-liste") and not(@id)]/tbody/tr'): - yield sub - return + class iter_funded_equities(TableElement): + item_xpath = '//table[@id="table-portefeuille-titres-participatifs"]/tbody/tr' + head_xpath = '//table[@id="table-portefeuille-titres-participatifs"]/thead//th' - head_xpath = '//table[has-class("portefeuille-liste") and not(@id)]/thead//th' - col_label = 'Opération / Cible' - col_details = 'Détails' - - class item(ItemElement): - klass = Investment - - obj_label = CleanText(TableCell('label')) + col_bought = 'Vous avez investi' + col_label = 'Investissement dans' - # Can be "100,00 € + Frais de 0,90 €" or "€100.00" - obj_valuation = Coalesce( - CleanDecimal.French(Regexp(CleanText(TableCell('details')), r'^(.*?) €', default=None), default=None), - CleanDecimal.US(Regexp(CleanText(TableCell('details')), r'^€([^ ]+)', default=None), default=None), - ) + class item(FundItemElement): + pass