Add history of calls on freemobile module

This commit is contained in:
Florent 2012-03-13 19:22:24 +01:00 committed by Romain Bignon
commit 5fac5421eb
4 changed files with 39 additions and 14 deletions

View file

@ -64,7 +64,9 @@ class FreeMobileBackend(BaseBackend, ICapBill):
raise SubscriptionNotFound() raise SubscriptionNotFound()
def iter_history(self, subscription): def iter_history(self, subscription):
raise NotImplementedError() with self.browser:
for history in self.browser.get_history():
yield history
def get_get_bill(self, subscription, id): def get_get_bill(self, subscription, id):
raise NotImplementedError() raise NotImplementedError()

View file

@ -19,7 +19,7 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from .pages import HomePage, LoginPage, HistoryPage from .pages import HomePage, LoginPage, HistoryPage, DetailsPage
__all__ = ['Freemobile'] __all__ = ['Freemobile']
@ -30,7 +30,8 @@ class Freemobile(BaseBrowser):
ENCODING = None # refer to the HTML encoding ENCODING = None # refer to the HTML encoding
PAGES = {'.*moncompte/index.php': LoginPage, PAGES = {'.*moncompte/index.php': LoginPage,
'.*page=home': HomePage, '.*page=home': HomePage,
'.*page=suiviconso': HistoryPage '.*page=suiviconso': DetailsPage,
'.*page=consotel_current_month': HistoryPage
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -74,14 +75,13 @@ class Freemobile(BaseBrowser):
return None return None
# XXX : not implemented
def get_history(self): def get_history(self):
if not self.is_on_page(HistoryPage): if not self.is_on_page(HistoryPage):
self.location('/moncompte/index.php?page=suiviconso') self.location('/moncompte/ajax.php?page=consotel_current_month', 'login=' + self.username)
return self.page.get_calls() return self.page.get_calls()
def get_details(self): def get_details(self):
if not self.is_on_page(HistoryPage): if not self.is_on_page(DetailsPage):
self.location('/moncompte/index.php?page=suiviconso') self.location('/moncompte/index.php?page=suiviconso')
test = self.page.get_details() test = self.page.get_details()
return test return test

View file

@ -19,7 +19,7 @@
from .homepage import HomePage from .homepage import HomePage
from .history import HistoryPage from .history import HistoryPage, DetailsPage
from .login import LoginPage from .login import LoginPage
__all__ = ['LoginPage', 'HomePage', 'HistoryPage'] __all__ = ['LoginPage', 'HomePage', 'HistoryPage', 'DetailsPage']

View file

@ -20,8 +20,10 @@
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bill import Detail from weboob.capabilities.bill import Detail
from datetime import datetime, date, time
__all__ = ['HistoryPage']
__all__ = ['HistoryPage', 'DetailsPage']
def convert_price(div): def convert_price(div):
@ -33,8 +35,7 @@ def convert_price(div):
return 0. return 0.
class HistoryPage(BasePage): class DetailsPage(BasePage):
calls = []
details = [] details = []
def on_loaded(self): def on_loaded(self):
@ -68,8 +69,30 @@ class HistoryPage(BasePage):
self.details.append(detail) self.details.append(detail)
def get_calls(self):
return self.calls
def get_details(self): def get_details(self):
return self.details return self.details
class HistoryPage(BasePage):
calls = []
def on_loaded(self):
for tr in self.document.xpath('//tr'):
tds = tr.xpath('td')
if tds[0].text == None or tds[0].text == "Date":
pass
else:
detail = Detail()
mydate = date(*reversed([int(x) for x in tds[0].text.split(' ')[0].split("/")]))
mytime = time(*[int(x) for x in tds[0].text.split(' ')[1].split(":")])
detail.datetime = datetime.combine(mydate, mytime)
detail.label = tds[1].text + " " + tds[2].text + " " + tds[3].text
try:
detail.price = float(tds[4].text[0:4].replace(',', '.'))
except:
detail.price = 0.
self.calls.append(detail)
def get_calls(self):
return self.calls