From a9535b269c7257acbc30ba0ce81b54787d593b1d Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Wed, 13 May 2020 18:54:29 +0200 Subject: [PATCH] [linebourse] Handle foreign books separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On some connections, the request with index 4 (Bourse étrangère) returns a 400 error so we handle it separately than the other order books. --- modules/linebourse/browser.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/linebourse/browser.py b/modules/linebourse/browser.py index 3d6801a1ff..ed23bb7f4e 100644 --- a/modules/linebourse/browser.py +++ b/modules/linebourse/browser.py @@ -20,6 +20,7 @@ from __future__ import unicode_literals from weboob.browser import LoginBrowser, URL +from weboob.browser.exceptions import ClientError from weboob.tools.capabilities.bank.transactions import sorted_transactions from .pages import ( @@ -75,13 +76,25 @@ def iter_market_orders(self, account_id): account_code = self.get_account_code(account_id) market_orders = [] - for index in range(5): - # Each index from 0 to 4 corresponds to various order books: - # 'Titres', 'Bourse étrangère'... + # Each index from 0 to 4 corresponds to various order books types. + # For some connections, the request with index 4 (foreign orders) + # returns a 400 error so we must handle it accordingly. + for index in range(4): self.market_order.go( account_code=account_code, index=index, ) market_orders.extend(self.page.iter_market_orders()) + # Try to fetch market orders on 'Carnet d'ordres Bourse étrangère' + try: + self.market_order.go( + account_code=account_code, + index=4, + ) + except ClientError: + self.logger.warning('Foreign orders book is not accessible for this account.') + else: + market_orders.extend(self.page.iter_market_orders()) + return sorted(market_orders, reverse=True, key=lambda order: order.date) -- GitLab