Support multiple account for details operation

This commit is contained in:
Florent 2012-08-27 14:54:50 +02:00
commit adce6d0c83
4 changed files with 59 additions and 45 deletions

View file

@ -50,8 +50,7 @@ class FreeMobileBackend(BaseBackend, ICapBill):
self.config['password'].get())
def iter_subscription(self):
for subscription in self.browser.get_subscription_list():
yield subscription
return self.browser.get_subscription_list()
def get_subscription(self, _id):
if not _id.isdigit():
@ -64,10 +63,14 @@ class FreeMobileBackend(BaseBackend, ICapBill):
raise SubscriptionNotFound()
def iter_history(self, subscription):
if not isinstance(subscription, Subscription):
subscription = self.get_subscription(subscription)
with self.browser:
for history in self.browser.get_history():
for history in self.browser.get_history(subscription):
yield history
def get_bill(self, id):
with self.browser:
bill = self.browser.get_bill(id)
@ -76,6 +79,7 @@ class FreeMobileBackend(BaseBackend, ICapBill):
else:
raise BillNotFound()
def iter_bills(self, subscription):
if not isinstance(subscription, Subscription):
subscription = self.get_subscription(subscription)
@ -84,12 +88,16 @@ class FreeMobileBackend(BaseBackend, ICapBill):
for bill in self.browser.iter_bills(subscription.id):
yield bill
# The subscription is actually useless, but maybe for the futur...
def get_details(self, subscription):
if not isinstance(subscription, Subscription):
subscription = self.get_subscription(subscription)
with self.browser:
for detail in self.browser.get_details():
for detail in self.browser.get_details(subscription):
yield detail
def download_bill(self, bill):
if not isinstance(bill, Bill):
bill = self.get_bill(bill)

View file

@ -68,22 +68,21 @@ class Freemobile(BaseBrowser):
if not self.is_on_page(HomePage):
self.location('/moncompte/index.php?page=home')
l = self.page.get_list()
for a in l:
for a in self.page.get_list():
if a.id == id:
return a
return None
def get_history(self):
def get_history(self, subscription):
if not self.is_on_page(HistoryPage):
self.location('/moncompte/ajax.php?page=consotel_current_month', 'login=' + self.username)
return self.page.get_calls()
return self.page.get_calls(subscription)
def get_details(self):
def get_details(self, subscription):
if not self.is_on_page(DetailsPage):
self.location('/moncompte/index.php?page=suiviconso')
return self.page.get_details()
return self.page.get_details(subscription)
def iter_bills(self, parentid):
if not self.is_on_page(DetailsPage):

View file

@ -22,7 +22,7 @@ from datetime import datetime, date, time
from decimal import Decimal
from weboob.tools.browser import BasePage
from weboob.capabilities.bill import Detail, Bill
from weboob.capabilities.bill import Detail, Bill, Subscription
import re
@ -41,18 +41,25 @@ def convert_price(div):
class DetailsPage(BasePage):
def on_loaded(self):
self.details = []
self.details = {}
self.datebills = []
num = self.document.xpath('//div[@class="infosLigneDetail pointer"]')[0].text
num = num.split("-")[2].strip()
for div in self.document.xpath('//div[@class="infosLigneDetail pointer"]'):
phonenumber = div.text
phonenumber = phonenumber.split("-")[2].strip()
virtualnumber = div.attrib['onclick'].split('(')[1][1]
self.details['num' + str(phonenumber)] = virtualnumber
# National parsing
divnat = self.document.xpath('//div[@class="national"]')[0]
self.parse_div(divnat, "National : %s | International : %s", False)
for div in self.document.xpath('//div[@class="infosConso"]'):
num = div.attrib['id'].split('_')[1][0]
self.details[num] = []
# International parsing
divint = self.document.xpath('//div[@class="international hide"]')[0]
self.parse_div(divint, u"Appels émis : %s | Appels reçus : %s", True)
# National parsing
divnat = div.xpath('div[@class="national"]')[0]
self.parse_div(divnat, "National : %s | International : %s", num, False)
# International parsing
divint = div.xpath('div[@class="international hide"]')[0]
self.parse_div(divint, u"Appels émis : %s | Appels reçus : %s", num, True)
for trbill in self.document.xpath('//tr[@class="derniereFacture"]'):
mydate = unicode(trbill.find('td').text.split(":")[1].strip())
@ -60,7 +67,7 @@ class DetailsPage(BasePage):
bill.label = unicode(mydate)
billid = mydate.replace('-', '')
billid = billid[4:8] + billid[2:4] + billid[0:2]
bill.id = num + "." + billid
bill.id = phonenumber + "." + billid
bill.date = date(*reversed([int(x) for x in mydate.split("-")]))
alink = trbill.find('td/a')
if alink.attrib.get("class") == "linkModal tips":
@ -71,15 +78,15 @@ class DetailsPage(BasePage):
bill._url = alink.attrib.get('href')
self.datebills.append(bill)
def parse_div(self, divglobal, string, inter=False):
def parse_div(self, divglobal, string, num, inter=False):
divs = divglobal.xpath('div[@class="detail"]')
# Two informations in one div...
div = divs.pop(0)
voice = self.parse_voice(div, string, inter)
self.details.append(voice)
self.iter_divs(divs, inter)
self.details[num].append(voice)
self.iter_divs(divs, num, inter)
def iter_divs(self, divs, inter=False):
def iter_divs(self, divs, num, inter=False):
for div in divs:
detail = Detail()
@ -89,7 +96,7 @@ class DetailsPage(BasePage):
detail.infos = unicode(div.find('div[@class="consoDetail"]/p').text_content().lstrip())
detail.price = convert_price(div)
self.details.append(detail)
self.details[num].append(detail)
def parse_voice(self, div, string, inter=False):
voice = Detail()
@ -103,8 +110,10 @@ class DetailsPage(BasePage):
return voice
def get_details(self):
return self.details
def get_details(self, subscription):
print self.details
num = self.details['num' + subscription.id]
return self.details[num]
def date_bills(self):
return self.datebills
@ -136,5 +145,5 @@ class HistoryPage(BasePage):
self.calls.append(detail)
def get_calls(self):
def get_calls(self, subscription):
return sorted(self.calls, key=_get_date, reverse=True)

View file

@ -30,18 +30,16 @@ class HomePage(BasePage):
def get_list(self):
l = []
divabo = self.document.xpath('//div[@class="idAbonne pointer"]')[0]
owner = unicode(divabo.xpath('p')[0].text.replace(' - ', ''))
phone = unicode(divabo.xpath('p/span')[0].text)
self.browser.logger.debug('Found ' + owner + ' has subscriber')
self.browser.logger.debug('Found ' + phone + ' has phone number')
phoneplan = unicode(self.document.xpath('//div[@class="forfaitChoisi"]')[0].text.lstrip().rstrip())
self.browser.logger.debug('Found ' + phoneplan + ' has subscription type')
for divabo in self.document.xpath('//div[@class="idAbonne pointer"]'):
owner = unicode(divabo.xpath('p')[0].text.replace(' - ', ''))
phone = unicode(divabo.xpath('p/span')[0].text)
self.browser.logger.debug('Found ' + owner + ' as subscriber')
self.browser.logger.debug('Found ' + phone + ' as phone number')
phoneplan = unicode(self.document.xpath('//div[@class="forfaitChoisi"]')[0].text.lstrip().rstrip())
self.browser.logger.debug('Found ' + phoneplan + ' as subscription type')
subscription = Subscription(phone)
subscription.label = phone + ' - ' + phoneplan
subscription.subscriber = owner
subscription = Subscription(phone)
subscription.label = phone + ' - ' + phoneplan
subscription.subscriber = owner
l.append(subscription)
return l
yield subscription