From 148089329dbfff1ca08d697234624f5e00700f5c Mon Sep 17 00:00:00 2001 From: Florent Date: Mon, 2 Jun 2014 13:53:46 +0200 Subject: [PATCH] Fix: do not crash if balance is notavailable --- modules/leclercmobile/backend.py | 4 ++-- modules/leclercmobile/browser.py | 17 ++++++++++++----- modules/leclercmobile/pages/history.py | 8 -------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/modules/leclercmobile/backend.py b/modules/leclercmobile/backend.py index ae56291b..8158e487 100644 --- a/modules/leclercmobile/backend.py +++ b/modules/leclercmobile/backend.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . - from weboob.capabilities.bill import ICapBill, SubscriptionNotFound,\ BillNotFound, Subscription, Bill from weboob.tools.backend import BaseBackend, BackendConfig @@ -67,7 +66,8 @@ class LeclercMobileBackend(BaseBackend, ICapBill): def iter_bills_history(self, subscription): with self.browser: for history in self.browser.get_history(): - yield history + if history.label != "Votre solde": + yield history def get_bill(self, id): with self.browser: diff --git a/modules/leclercmobile/browser.py b/modules/leclercmobile/browser.py index e384ca6d..633fb4f4 100644 --- a/modules/leclercmobile/browser.py +++ b/modules/leclercmobile/browser.py @@ -22,6 +22,9 @@ import StringIO from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from .pages import HomePage, LoginPage, HistoryPage, PdfPage +from weboob.capabilities.bill import Detail +from weboob.capabilities.base import NotAvailable + __all__ = ['Leclercmobile'] @@ -109,8 +112,7 @@ class Leclercmobile(BaseBrowser): pdf = PdfPage(StringIO.StringIO(response.read())) for call in pdf.get_calls(): call.label = call.label.strip() - if call.label != "Votre solde": - yield call + yield call def get_details(self): if not self.is_on_page(HistoryPage): @@ -140,6 +142,11 @@ class Leclercmobile(BaseBrowser): def get_balance(self): if not self.is_on_page(HistoryPage): self.location(self.conso) - response = self.openurl(self.bills + "0") - pdf = PdfPage(StringIO.StringIO(response.read())) - return pdf.get_balance() + detail = Detail() + detail.label = u"Balance" + for calls in self.get_history(): + if "Votre solde" in calls.label: + detail.price = calls.price + return detail + detail.price = NotAvailable + return detail diff --git a/modules/leclercmobile/pages/history.py b/modules/leclercmobile/pages/history.py index 7b3029fa..d0892eb5 100644 --- a/modules/leclercmobile/pages/history.py +++ b/modules/leclercmobile/pages/history.py @@ -93,14 +93,6 @@ class PdfPage(): details.append(detail) return details - def get_balance(self): - for calls in self.get_calls(): - if "Votre solde" in calls.label: - detail = Detail() - detail.price = calls.price - detail.label = u"Balance" - return detail - # Standard pdf text extractor take text line by line # But the position in the file is not always the "real" position to display... # It produce some unsorted and unparsable data