From 0734e5d21c6efed2757b5b2731e9a6b92b27a9b0 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 10 Feb 2012 08:23:34 +0100 Subject: [PATCH] CrAgr: now handles history-less accounts, at least for Toulouse-like layouts --- modules/cragr/browser.py | 3 +++ modules/cragr/pages/accounts_list.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/cragr/browser.py b/modules/cragr/browser.py index 603b3161..2b0c0a68 100644 --- a/modules/cragr/browser.py +++ b/modules/cragr/browser.py @@ -131,6 +131,9 @@ class Cragr(BaseBrowser): return None def get_history(self, account): + # some accounts may exist without a link to any history page + if account.link_id is None: + return history_url = account.link_id operations_count = 0 diff --git a/modules/cragr/pages/accounts_list.py b/modules/cragr/pages/accounts_list.py index 65df9ffc..d377c229 100644 --- a/modules/cragr/pages/accounts_list.py +++ b/modules/cragr/pages/accounts_list.py @@ -46,18 +46,26 @@ class AccountsList(CragrBasePage): account = Account() if div.getchildren()[0].tag == 'a': # This is at least present on CA Nord-Est + # Note: we do not know yet how history-less accounts are displayed by this layout account.label = ' '.join(div.find('a').text.split()[:-1]) account.link_id = div.find('a').get('href', '') account.id = div.find('a').text.split()[-1] s = div.find('div').find('b').find('span').text else: # This is at least present on CA Toulouse - account.label = div.find('a').text.strip() - account.link_id = div.find('a').get('href', '') + first_link = div.find('a') + if first_link is not None: + account.label = first_link.text.strip() + account.link_id = first_link.get('href', '') + else: + # there is no link to any history page for accounts like "PEA" or "TITRES" + account.label = div.findall('br')[0].tail.strip() + account.link_id = None account.id = div.findall('br')[1].tail.strip() - s = div.find('div').find('b').text + s = div.xpath('//b')[-1].text account.balance = clean_amount(s) - l.append(account) + if account.label: + l.append(account) return l def is_accounts_list(self):