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/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from weboob.capabilities.bill import ICapBill, SubscriptionNotFound,\
|
from weboob.capabilities.bill import ICapBill, SubscriptionNotFound,\
|
||||||
BillNotFound, Subscription, Bill
|
BillNotFound, Subscription, Bill
|
||||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||||
|
|
@ -67,7 +66,8 @@ class LeclercMobileBackend(BaseBackend, ICapBill):
|
||||||
def iter_bills_history(self, subscription):
|
def iter_bills_history(self, subscription):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
for history in self.browser.get_history():
|
for history in self.browser.get_history():
|
||||||
yield history
|
if history.label != "Votre solde":
|
||||||
|
yield history
|
||||||
|
|
||||||
def get_bill(self, id):
|
def get_bill(self, id):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ import StringIO
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
from .pages import HomePage, LoginPage, HistoryPage, PdfPage
|
from .pages import HomePage, LoginPage, HistoryPage, PdfPage
|
||||||
|
from weboob.capabilities.bill import Detail
|
||||||
|
from weboob.capabilities.base import NotAvailable
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Leclercmobile']
|
__all__ = ['Leclercmobile']
|
||||||
|
|
||||||
|
|
@ -109,8 +112,7 @@ class Leclercmobile(BaseBrowser):
|
||||||
pdf = PdfPage(StringIO.StringIO(response.read()))
|
pdf = PdfPage(StringIO.StringIO(response.read()))
|
||||||
for call in pdf.get_calls():
|
for call in pdf.get_calls():
|
||||||
call.label = call.label.strip()
|
call.label = call.label.strip()
|
||||||
if call.label != "Votre solde":
|
yield call
|
||||||
yield call
|
|
||||||
|
|
||||||
def get_details(self):
|
def get_details(self):
|
||||||
if not self.is_on_page(HistoryPage):
|
if not self.is_on_page(HistoryPage):
|
||||||
|
|
@ -140,6 +142,11 @@ class Leclercmobile(BaseBrowser):
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
if not self.is_on_page(HistoryPage):
|
if not self.is_on_page(HistoryPage):
|
||||||
self.location(self.conso)
|
self.location(self.conso)
|
||||||
response = self.openurl(self.bills + "0")
|
detail = Detail()
|
||||||
pdf = PdfPage(StringIO.StringIO(response.read()))
|
detail.label = u"Balance"
|
||||||
return pdf.get_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)
|
details.append(detail)
|
||||||
return details
|
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
|
# Standard pdf text extractor take text line by line
|
||||||
# But the position in the file is not always the "real" position to display...
|
# But the position in the file is not always the "real" position to display...
|
||||||
# It produce some unsorted and unparsable data
|
# It produce some unsorted and unparsable data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue