From 8950d2539f22877d997f49ce8ddb29af4adc3010 Mon Sep 17 00:00:00 2001 From: Baptiste Delpey Date: Mon, 8 Jun 2015 16:35:04 +0200 Subject: [PATCH] handle new americanexpress site but only if there is only one card --- modules/americanexpress/browser.py | 16 ++++++++++------ modules/americanexpress/pages.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/modules/americanexpress/browser.py b/modules/americanexpress/browser.py index 2fc95ccb..21e230a5 100644 --- a/modules/americanexpress/browser.py +++ b/modules/americanexpress/browser.py @@ -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) diff --git a/modules/americanexpress/pages.py b/modules/americanexpress/pages.py index 7a92af3d..573197ce 100644 --- a/modules/americanexpress/pages.py +++ b/modules/americanexpress/pages.py @@ -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'):