Support bills and download operations

This commit is contained in:
Florent 2012-08-29 14:25:52 +02:00
commit f33af8ff50
2 changed files with 18 additions and 7 deletions

View file

@ -120,14 +120,12 @@ class Leclercmobile(BaseBrowser):
def iter_bills(self, parentid): def iter_bills(self, parentid):
if not self.is_on_page(HistoryPage): if not self.is_on_page(HistoryPage):
self.location(self.conso) self.location(self.conso)
return self.page.date_bills() return self.page.date_bills(parentid)
def get_bill(self, id): def get_bill(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)
parentid = id[0:10]
if not self.is_on_page(HistoryPage): l = self.page.date_bills(parentid)
self.location(self.conso)
l = self.page.date_bills()
for a in l: for a in l:
if a.id == id: if a.id == id:
return a return a

View file

@ -26,7 +26,7 @@ from datetime import datetime, date, time
from decimal import Decimal from decimal import Decimal
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bill import Detail from weboob.capabilities.bill import Detail, Bill
__all__ = ['HistoryPage', 'PdfPage'] __all__ = ['HistoryPage', 'PdfPage']
@ -62,7 +62,7 @@ class PdfPage():
lines = page.split('\n') lines = page.split('\n')
lines = [x for x in lines if len(x) > 0] # Remove empty lines lines = [x for x in lines if len(x) > 0] # Remove empty lines
numitems = (len(lines) + 1) / 3 # Each line has three columns numitems = (len(lines) + 1) / 3 # Each line has three columns
lines.insert(len(lines), '') # Add an empty column for "Prélèvement mensuel lines.insert(len(lines) - 1, '') # Add an empty column for "Prélèvement mensuel
lines.pop(0) lines.pop(0)
details = [] details = []
for i in range(numitems): for i in range(numitems):
@ -134,3 +134,16 @@ class HistoryPage(BasePage):
while len(self.document.xpath('//li[@id="liMois%s"]' % max)) > 0: while len(self.document.xpath('//li[@id="liMois%s"]' % max)) > 0:
max += 1 max += 1
return max - 1 return max - 1
def date_bills(self, parentid):
max = 1
while len(self.document.xpath('//li[@id="liMois%s"]' % max)) > 0:
li = self.document.xpath('//li[@id="liMois%s"]' % max)[0]
max += 1
link = li.xpath('a')[0]
bill = Bill()
bill._url = link.attrib['href']
bill.label = link.text
bill.format = u"pdf"
bill.id = parentid + bill.label.replace(' ', '')
yield bill