From e8c387aa024a735505787d3e082dd145b2a9a4f3 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 3 Apr 2014 14:53:12 +0200 Subject: [PATCH] Make history working with browser2 --- modules/freemobile/browser.py | 3 ++- modules/freemobile/pages/history.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/freemobile/browser.py b/modules/freemobile/browser.py index dffe4f17..46e92193 100644 --- a/modules/freemobile/browser.py +++ b/modules/freemobile/browser.py @@ -49,12 +49,13 @@ class Freemobile(LoginBrowser): self.detailspage.go() for subscription in subscriptions: + subscription._virtual = self.page.load_virtual(subscription.id) subscription.renewdate = self.page.get_renew_date(subscription) yield subscription def get_history(self, subscription): self.historypage.go(data={'login': subscription._login}) - return self.page.get_calls() + return sorted([x for x in self.page.get_calls()], key=lambda self: self.datetime, reverse=True) def get_details(self, subscription): return self.detailspage.stay_or_go().get_details(subscription) diff --git a/modules/freemobile/pages/history.py b/modules/freemobile/pages/history.py index 16f365c8..135f2cf7 100644 --- a/modules/freemobile/pages/history.py +++ b/modules/freemobile/pages/history.py @@ -45,14 +45,13 @@ class BadUTF8Page(HTMLPage): class DetailsPage(LoggedPage, BadUTF8Page): + def load_virtual(self, phonenumber): + for div in self.doc.xpath('//div[@class="infosLigne pointer"]'): + if CleanText('.')(div).split("-")[-1].strip() == phonenumber: + return Attr('.', 'onclick')(div).split('(')[1][1] + def on_load(self): self.details = {} - for div in self.doc.xpath('//div[@class="infosLigne pointer"]'): - phonenumber = CleanText('.')(div) - phonenumber = phonenumber.split("-")[-1].strip() - virtualnumber = div.attrib['onclick'].split('(')[1][1] - self.details['num' + str(phonenumber)] = virtualnumber - for div in self.doc.xpath('//div[@class="infosConso"]'): num = div.attrib['id'].split('_')[1][0] self.details[num] = [] @@ -104,8 +103,7 @@ class DetailsPage(LoggedPage, BadUTF8Page): # XXX def get_details(self, subscription): - num = self.details['num' + subscription.id] - for detail in self.details[num]: + for detail in self.details[subscription._virtual]: detail.id = subscription.id + detail.id yield detail @@ -151,7 +149,8 @@ class HistoryPage(LoggedPage, BadUTF8Page): txt = self.el.xpath('td[1]')[0].text return (txt is not None) and (txt != "Date") - obj_datetime = DateTime(CleanText('td[1]'), dayfirst=True) - obj_label = Format(u'%s %s %s %s', CleanText('td[2]'), CleanText('td[3]'), - CleanText('td[4]'), CleanText('td[5]')) + obj_id = None + obj_datetime = DateTime(CleanText('td[1]', symbols=u'à'), dayfirst=True) + obj_label = Format(u'%s %s %s', CleanText('td[2]'), CleanText('td[3]'), + CleanText('td[4]')) obj_price = CleanDecimal('td[5]', default=Decimal(0))