From c890fe26d7d14b09bdb383eff0b142744f35cd96 Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 13 Mar 2012 21:39:18 +0100 Subject: [PATCH] Search bills on freemobile --- modules/freemobile/backend.py | 10 +++++++--- modules/freemobile/browser.py | 8 ++++++-- modules/freemobile/pages/history.py | 14 +++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/freemobile/backend.py b/modules/freemobile/backend.py index ac6c9120..20f8fc4d 100644 --- a/modules/freemobile/backend.py +++ b/modules/freemobile/backend.py @@ -68,11 +68,15 @@ class FreeMobileBackend(BaseBackend, ICapBill): for history in self.browser.get_history(): yield history - def get_get_bill(self, subscription, id): + def get_bill(self, subscription, id): raise NotImplementedError() - def iter_bill(self, subscription): - raise NotImplementedError() + def iter_bills(self, subscription): + with self.browser: + sub = self.get_subscription(subscription) + for bill in self.browser.iter_bills(): + bill.idparent = sub.id + yield bill # The subscription is actually useless, but maybe for the futur... def get_details(self, subscription): diff --git a/modules/freemobile/browser.py b/modules/freemobile/browser.py index 6324fc7c..873c641e 100644 --- a/modules/freemobile/browser.py +++ b/modules/freemobile/browser.py @@ -83,5 +83,9 @@ class Freemobile(BaseBrowser): def get_details(self): if not self.is_on_page(DetailsPage): self.location('/moncompte/index.php?page=suiviconso') - test = self.page.get_details() - return test + return self.page.get_details() + + def iter_bills(self): + if not self.is_on_page(DetailsPage): + self.location('/moncompte/index.php?page=suiviconso') + return self.page.date_bills() diff --git a/modules/freemobile/pages/history.py b/modules/freemobile/pages/history.py index 20c75f42..1e3c2c29 100644 --- a/modules/freemobile/pages/history.py +++ b/modules/freemobile/pages/history.py @@ -19,7 +19,7 @@ from weboob.tools.browser import BasePage -from weboob.capabilities.bill import Detail +from weboob.capabilities.bill import Detail, Bill from datetime import datetime, date, time @@ -37,6 +37,7 @@ def convert_price(div): class DetailsPage(BasePage): details = [] + datebills = [] def on_loaded(self): @@ -57,6 +58,14 @@ class DetailsPage(BasePage): divint = self.document.xpath('//div[@class="international hide"]')[0] self.iter_divs(divint.xpath('div[@class="detail"]'), True) + for trbill in self.document.xpath('//tr[@class="derniereFacture"]'): + mydate = trbill.find('td/input').attrib['onclick'].split("'")[1] + bill = Bill() + bill.label = mydate + bill.date = date(int(mydate[0:4]), int(mydate[4:6]), int(mydate[6:8])) + bill.format = 'html' + self.datebills.append(bill) + def iter_divs(self, divs, inter=False): for div in divs: detail = Detail() @@ -72,6 +81,9 @@ class DetailsPage(BasePage): def get_details(self): return self.details + def date_bills(self): + return self.datebills + def _get_date(detail): return detail.datetime