handle new americanexpress site but only if there is only one card

This commit is contained in:
Baptiste Delpey 2015-06-08 16:35:04 +02:00 committed by Romain Bignon
commit 8950d2539f
2 changed files with 27 additions and 6 deletions

View file

@ -22,7 +22,7 @@ from urlparse import urlsplit, parse_qsl
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
from .pages import LoginPage, AccountsPage, TransactionsPage
from .pages import LoginPage, AccountsPage, TransactionsPage, NewAccountsPage
__all__ = ['AmericanExpressBrowser']
@ -34,6 +34,7 @@ class AmericanExpressBrowser(Browser):
ENCODING = 'ISO-8859-1'
PAGES = {'https://global.americanexpress.com/myca/logon/.*': LoginPage,
'https://global.americanexpress.com/myca/intl/acctsumm/.*': AccountsPage,
'https://global.americanexpress.com/myca/intl/isummary/.*': NewAccountsPage,
'https://global.americanexpress.com/myca/intl/estatement/.*': TransactionsPage,
}
@ -64,7 +65,7 @@ class AmericanExpressBrowser(Browser):
self.submit()
def get_accounts_list(self):
if not self.is_on_page(AccountsPage):
if not self.is_on_page(AccountsPage) and not self.is_on_page(NewAccountsPage):
self.go_on_accounts_list()
return self.page.get_list()
@ -79,15 +80,18 @@ class AmericanExpressBrowser(Browser):
return None
def get_history(self, account):
if not self.is_on_page(AccountsPage):
if not self.is_on_page(AccountsPage) and not self.is_on_page(NewAccountsPage):
self.go_on_accounts_list()
url = account._link
while url is not None:
self.select_form(name='leftnav')
self.form.action = self.absurl(url)
self.submit()
if self.is_on_page(NewAccountsPage):
self.location(url)
else:
self.select_form(name='leftnav')
self.form.action = self.absurl(url)
self.submit()
assert self.is_on_page(TransactionsPage)

View file

@ -40,6 +40,23 @@ class LoginPage(Page):
self.browser.submit(nologin=True)
class NewAccountsPage(Page):
def get_list(self):
for div in self.document.xpath('.//div[@id="card-details"]'):
a = Account()
a.id = self.parser.tocleanstring(div.xpath('.//span[@class="acc-num"]')[0])
a.label =self.parser.tocleanstring( div.xpath('.//span[@class="card-desc"]')[0])
balance = self.parser.tocleanstring(div.xpath('.//span[@class="balance-data"]')[0])
if balance in (u'Indisponible', u'Indisponible Facturation en cours', ''):
a.balance = NotAvailable
else:
a.balance = - abs(Decimal(Transaction.clean_amount(balance)))
a.currency = a.get_currency(balance)
a._link = self.document.xpath('.//div[@class="wide-bar"]/h3/a')[0].attrib['href']
yield a
class AccountsPage(Page):
def get_list(self):
for box in self.document.getroot().cssselect('div.roundedBox div.contentBox'):