From e04bc24fcab5cee0dbbded61b348f4dd623b88c8 Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Wed, 13 Feb 2019 11:27:06 +0100 Subject: [PATCH] [barclays] Corrected iter_accounts to fetch IBANs The is_here() of the LoansPage was catching most other accounts pages, as a results, we never landed on AbstractAccountPage and therefore, has_iban() always returned False and we were not fetching the IBANs anymore. I changed the is_here so that every account fits with the right Page. From what I observed, only checking accounts have an IBAN so there is no need to go to every account's detail page during iter_accounts if we do not scrape anything on it. This modification significantly reduces the number of requests and the duration of iter_accounts(). --- modules/barclays/browser.py | 12 +++++++++--- modules/barclays/pages.py | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/barclays/browser.py b/modules/barclays/browser.py index 08574d4e85..ae252b919a 100644 --- a/modules/barclays/browser.py +++ b/modules/barclays/browser.py @@ -131,11 +131,17 @@ def iter_accounts(self): traccounts = [] for account in accounts: - self._go_to_account(account) + if account.type == Account.TYPE_CHECKING: + # Only checking accounts have an IBAN + self._go_to_account(account) + account.iban = self.iban.open().get_iban() if self.page.has_iban() else NotAvailable + if account.type == Account.TYPE_LOAN: + self._go_to_account(account) account = self.page.get_loan_attributes(account) if account.type == Account.TYPE_CARD: + self._go_to_account(account) if self.page.is_immediate_card(): account.type = Account.TYPE_CHECKING @@ -143,11 +149,11 @@ def iter_accounts(self): continue account._attached_account = self.page.do_account_attachment([a for a in accounts if a.type == Account.TYPE_CHECKING]) + if account.type == Account.TYPE_REVOLVING_CREDIT: + self._go_to_account(account) account = self.page.get_revolving_attributes(account) - account.iban = self.iban.open().get_iban() if self.page.has_iban() else NotAvailable - traccounts.append(account) self.cache['accounts'] = traccounts diff --git a/modules/barclays/pages.py b/modules/barclays/pages.py index e703dd176c..c80287fe1e 100644 --- a/modules/barclays/pages.py +++ b/modules/barclays/pages.py @@ -109,6 +109,7 @@ class AccountsPage(StatefulPage): 'E VIE MILLEIS': Account.TYPE_LIFE_INSURANCE, 'BANQUE PRIVILEGE': Account.TYPE_REVOLVING_CREDIT, 'PRET PERSONNEL': Account.TYPE_LOAN, + 'CREDIT IMMOBILIE': Account.TYPE_LOAN, } ACCOUNT_TYPE_TO_STR = {Account.TYPE_MARKET: 'TTR', Account.TYPE_CARD: 'CRT' @@ -470,7 +471,7 @@ def get_revolving_attributes(self, account): class LoanAccountPage(AbstractAccountPage): def is_here(self): - return bool(CleanText('//span[contains(., "Détail compte")]')(self.doc)) + return bool(CleanText('//span[contains(., "prêt")]')(self.doc)) def has_iban(self): return False -- GitLab