From 7629ef1735ff2cb4373ab9d61c1ed5ae8ecbdc6d Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Thu, 7 May 2015 08:14:20 +0200 Subject: [PATCH] Detect connection errors --- modules/cragr/web/browser.py | 2 +- modules/cragr/web/pages.py | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/cragr/web/browser.py b/modules/cragr/web/browser.py index f9ba05b7..fb99c5e0 100644 --- a/modules/cragr/web/browser.py +++ b/modules/cragr/web/browser.py @@ -62,7 +62,7 @@ class Cragr(Browser): self.login() def is_logged(self): - return self.page is not None and not self.is_on_page(HomePage) + return self.page is not None and not self.is_on_page(HomePage) and self.page.get_error() is None def login(self): """ diff --git a/modules/cragr/web/pages.py b/modules/cragr/web/pages.py index 5f4073b4..c270f3ca 100644 --- a/modules/cragr/web/pages.py +++ b/modules/cragr/web/pages.py @@ -26,7 +26,17 @@ from weboob.deprecated.browser import Page, BrokenPageError from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction -class HomePage(Page): +class BasePage(Page): + def get_error(self): + try: + error = self.document.xpath('//h1[@class="h1-erreur"]')[0] + self.logger.error('Error detected: %s', error.text_content().strip()) + return error + except IndexError: + return None + + +class HomePage(BasePage): def get_post_url(self): for script in self.document.xpath('//script'): text = script.text @@ -40,7 +50,7 @@ class HomePage(Page): return None -class LoginPage(Page): +class LoginPage(BasePage): def login(self, password): imgmap = {} for td in self.document.xpath('//table[@id="pave-saisie-code"]/tr/td'): @@ -59,15 +69,15 @@ class LoginPage(Page): return self.parser.tocleanstring(self.document.getroot()) -class UselessPage(Page): +class UselessPage(BasePage): pass -class LoginErrorPage(Page): +class LoginErrorPage(BasePage): pass -class _AccountsPage(Page): +class _AccountsPage(BasePage): COL_LABEL = 0 COL_ID = 2 COL_VALUE = 4 @@ -136,7 +146,7 @@ class _AccountsPage(Page): return links -class CardsPage(Page): +class CardsPage(BasePage): def get_list(self): TABLE_XPATH = '//table[caption[@class="caption tdb-cartes-caption" or @class="ca-table caption"]]' @@ -247,7 +257,8 @@ class SavingsPage(_AccountsPage): COL_ID = 1 -class TransactionsPage(Page): + +class TransactionsPage(BasePage): def get_iban_url(self): for link in self.document.xpath('//a[contains(text(), "IBAN")]'): m = re.search("\('([^']+)'", link.get('href', ''))