Fix: do not crash if balance is notavailable
This commit is contained in:
parent
a8fad76245
commit
148089329d
3 changed files with 14 additions and 15 deletions
|
|
@ -18,7 +18,6 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue