From b0498473fbfb4593ffd6d7575b7a1495beee2879 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sun, 28 Jul 2013 16:01:41 +0200 Subject: [PATCH] bnppe: do not crash with securities accounts --- modules/bnporc/enterprise/browser.py | 11 +++++++---- modules/bnporc/enterprise/pages.py | 13 +++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/bnporc/enterprise/browser.py b/modules/bnporc/enterprise/browser.py index efbcd017..cf8aa78d 100644 --- a/modules/bnporc/enterprise/browser.py +++ b/modules/bnporc/enterprise/browser.py @@ -73,9 +73,12 @@ class BNPEnterprise(BaseBrowser): yield a def iter_history(self, account): - if not self.is_on_page(HistoryPage): - self.location('/ROP?Action=F_RELCO&ch4=%s&ch8=2000' % account._link_id) - d1, d2 = self.page.get_date_range() - self.location('/ROP?Action=F_RELCO&ch4=%s&ch5=%s&ch9=%s&ch8=2000' % (account._link_id, d1, d2)) + if account._link_id is None: + return + + self.location('/ROP?Action=F_RELCO&ch4=%s&ch8=2000' % account._link_id) + d1, d2 = self.page.get_date_range() + self.location('/ROP?Action=F_RELCO&ch4=%s&ch5=%s&ch9=%s&ch8=2000' % (account._link_id, d1, d2)) + for transaction in self.page.iter_history(): yield transaction diff --git a/modules/bnporc/enterprise/pages.py b/modules/bnporc/enterprise/pages.py index 38afe5bf..5762f240 100644 --- a/modules/bnporc/enterprise/pages.py +++ b/modules/bnporc/enterprise/pages.py @@ -23,7 +23,7 @@ from urlparse import parse_qs from datetime import datetime from weboob.capabilities.bank import Account -from weboob.tools.browser import BasePage +from weboob.tools.browser import BasePage, BrokenPageError from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError from weboob.tools.misc import to_unicode @@ -117,7 +117,7 @@ class AccountsPage(BEPage): def find_table(self): for table in self.parser.select(self.document.getroot(), 'table', 'many'): for td in self.parser.select(table, 'tr td'): - if td.text and td.text.strip().startswith('COMPTES COURANTS'): + if td.text and td.text.strip().startswith('COMPTES '): return table def get_list(self): @@ -132,8 +132,13 @@ class AccountsPage(BEPage): account.label = to_unicode(tdlabel.text_content().strip()) # this is important - and is also the last part of the id (considering spaces) # we can't use only the link as it does not goes where we want - link = self.parser.select(tdlabel, 'a', 1) - account._link_id = parse_qs(link.attrib['href'])['ch4'][0] + try: + link = self.parser.select(tdlabel, 'a', 1) + except BrokenPageError: + # probably an account we can't display the history + account._link_id = None + else: + account._link_id = parse_qs(link.attrib['href'])['ch4'][0] account.id = to_unicode(tdid.text.strip().replace(' ', '')) # just in case we are showing the converted balances account._main_currency = Account.get_currency(tdcur.text)