From f8228243fabecf358d0a8a6f0603ad441620f2d9 Mon Sep 17 00:00:00 2001 From: Jerome Berthier Date: Thu, 4 Apr 2019 18:44:22 +0200 Subject: [PATCH] [myedenred] Update the module to support a new website behavior When people have more than one accounts, accounts information are not available from the main page. Both behaviors are now handled. --- modules/myedenred/browser.py | 10 +++++++--- modules/myedenred/module.py | 2 +- modules/myedenred/pages.py | 31 ++++++++++++++++++------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/modules/myedenred/browser.py b/modules/myedenred/browser.py index 696ffba9e3..3267f375cf 100644 --- a/modules/myedenred/browser.py +++ b/modules/myedenred/browser.py @@ -22,7 +22,7 @@ from weboob.browser import LoginBrowser, URL, need_login from weboob.exceptions import BrowserIncorrectPassword from weboob.tools.capabilities.bank.transactions import merge_iterators -from .pages import LoginPage, AccountsPage, TransactionsPage +from .pages import LoginPage, AccountsPage, AccountDetailsPage, TransactionsPage class MyedenredBrowser(LoginBrowser): @@ -31,6 +31,7 @@ class MyedenredBrowser(LoginBrowser): login = URL(r'/ctr\?Length=7', r'/ExtendedAccount/Logon', LoginPage) accounts = URL(r'/$', AccountsPage) + accounts_details = URL(r'/ExtendedHome/ProductLine\?benId=(?P\d+)', AccountDetailsPage) transactions = URL('/Card/TransactionSet', TransactionsPage) def __init__(self, *args, **kwargs): @@ -46,8 +47,11 @@ def do_login(self): raise BrowserIncorrectPassword @need_login - def get_accounts_list(self): - return self.accounts.stay_or_go().iter_accounts() + def iter_accounts(self): + for acc_id in self.accounts.stay_or_go().get_accounts_id(): + yield self.accounts_details.go(headers={'X-Requested-With': 'XMLHttpRequest'}, + token=acc_id).get_account() + @need_login def iter_history(self, account): diff --git a/modules/myedenred/module.py b/modules/myedenred/module.py index 3a3c87b532..494c46b1f9 100644 --- a/modules/myedenred/module.py +++ b/modules/myedenred/module.py @@ -47,7 +47,7 @@ def create_default_browser(self): return self.create_browser(self.config['login'].get(), self.config['password'].get()) def iter_accounts(self): - return self.browser.get_accounts_list() + return self.browser.iter_accounts() def get_account(self, id): return find_object(self.iter_accounts(), id=id, error=AccountNotFound) diff --git a/modules/myedenred/pages.py b/modules/myedenred/pages.py index 3372f2a574..2133bbf63b 100644 --- a/modules/myedenred/pages.py +++ b/modules/myedenred/pages.py @@ -20,7 +20,7 @@ from __future__ import unicode_literals -from weboob.browser.pages import HTMLPage, LoggedPage +from weboob.browser.pages import HTMLPage, PartialHTMLPage, LoggedPage from weboob.browser.elements import ItemElement, method, ListElement from weboob.browser.filters.standard import ( CleanText, CleanDecimal, @@ -43,22 +43,26 @@ def get_error(self): class AccountsPage(LoggedPage, HTMLPage): + def get_accounts_id(self): + for e in self.doc.xpath('//ul[@id="navSideProducts"]//strong[contains(text(), "Restaurant")]/ancestor::li'): + yield e.attrib['id'].split('_')[-1] + + +class AccountDetailsPage(LoggedPage, PartialHTMLPage): @method - class iter_accounts(ListElement): - item_xpath = '//ul[@id="navSideProducts"]/li' + class get_account(ItemElement): + klass = Account - class item(ItemElement): - klass = Account + obj_type = Account.TYPE_CARD + obj_id = CleanText('//p[contains(text(), "Identifiant")]/a') + obj_label = obj_id + obj_currency = u'EUR' + obj_balance = MyDecimal('//p[@class="num"]/a') - obj_type = Account.TYPE_CARD - obj_id = CleanText('./a/p', replace=[('N° ', '')]) - obj_label = obj_id - obj_currency = u'EUR' - obj_balance = MyDecimal(u'//p[@class="num"]//strong') + # Every subscription a product token and a type ex: card = 240 + obj__product_token = Regexp(CleanText('//div[contains(@id, "product")]/@id'), r'productLine_(\d*)') + obj__product_type = Regexp(CleanText('(//div[@class="logo"])[1]//img/@src'), "/img/product_(\d*).png") - # Every subscription a product token and a type ex: card = 240 - obj__product_token = Regexp(CleanText('./@id'), r'navSideProduct_(\d*)') - obj__product_type = Regexp(CleanText('(//div[@class="logo"])[1]//img/@src'), "/img/product_(\d*).png") class TransactionsPage(LoggedPage, HTMLPage): @@ -73,6 +77,7 @@ class item(ItemElement): obj_label = CleanText('.//h3/strong') obj_raw = Field('label') obj_amount = MyDecimal('./td[@class="al-r"]/div/span[has-class("badge")]') + def obj_type(self): amount = Field('amount')(self) if amount < 0: -- GitLab