From f33af8ff50aea0db20113dc28eb8dc58f6cd2110 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 29 Aug 2012 14:25:52 +0200 Subject: [PATCH] Support bills and download operations --- modules/leclercmobile/browser.py | 8 +++----- modules/leclercmobile/pages/history.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/leclercmobile/browser.py b/modules/leclercmobile/browser.py index b878bb4c..074d0b4f 100644 --- a/modules/leclercmobile/browser.py +++ b/modules/leclercmobile/browser.py @@ -120,14 +120,12 @@ class Leclercmobile(BaseBrowser): def iter_bills(self, parentid): if not self.is_on_page(HistoryPage): self.location(self.conso) - return self.page.date_bills() + return self.page.date_bills(parentid) def get_bill(self, id): assert isinstance(id, basestring) - - if not self.is_on_page(HistoryPage): - self.location(self.conso) - l = self.page.date_bills() + parentid = id[0:10] + l = self.page.date_bills(parentid) for a in l: if a.id == id: return a diff --git a/modules/leclercmobile/pages/history.py b/modules/leclercmobile/pages/history.py index 1821d4fa..2a91df69 100644 --- a/modules/leclercmobile/pages/history.py +++ b/modules/leclercmobile/pages/history.py @@ -26,7 +26,7 @@ from datetime import datetime, date, time from decimal import Decimal from weboob.tools.browser import BasePage -from weboob.capabilities.bill import Detail +from weboob.capabilities.bill import Detail, Bill __all__ = ['HistoryPage', 'PdfPage'] @@ -62,7 +62,7 @@ class PdfPage(): lines = page.split('\n') lines = [x for x in lines if len(x) > 0] # Remove empty lines 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) details = [] for i in range(numitems): @@ -134,3 +134,16 @@ class HistoryPage(BasePage): while len(self.document.xpath('//li[@id="liMois%s"]' % max)) > 0: 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