Commit f8228243 authored by Jerome Berthier's avatar Jerome Berthier Committed by Romain Bignon

[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.
parent 1394a3cd
......@@ -22,7 +22,7 @@ from __future__ import unicode_literals
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<token>\d+)', AccountDetailsPage)
transactions = URL('/Card/TransactionSet', TransactionsPage)
def __init__(self, *args, **kwargs):
......@@ -46,8 +47,11 @@ class MyedenredBrowser(LoginBrowser):
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):
......
......@@ -47,7 +47,7 @@ class MyedenredModule(Module, CapBank):
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)
......
......@@ -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 @@ class LoginPage(HTMLPage):
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 TransactionsPage(LoggedPage, HTMLPage):
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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment