Add multi-account support for bills

This commit is contained in:
Florent 2013-02-03 11:23:08 +01:00
commit c0fc9c7dd6
3 changed files with 29 additions and 23 deletions

View file

@ -83,7 +83,7 @@ class FreeMobileBackend(BaseBackend, ICapBill):
subscription = self.get_subscription(subscription) subscription = self.get_subscription(subscription)
with self.browser: with self.browser:
for bill in self.browser.iter_bills(subscription.id): for bill in self.browser.iter_bills(subscription):
yield bill yield bill
def get_details(self, subscription): def get_details(self, subscription):

View file

@ -91,10 +91,10 @@ class Freemobile(BaseBrowser):
self.location('/moncompte/index.php?page=suiviconso') self.location('/moncompte/index.php?page=suiviconso')
return self.page.get_details(subscription) return self.page.get_details(subscription)
def iter_bills(self, parentid): def iter_bills(self, subscription):
if not self.is_on_page(DetailsPage): if not self.is_on_page(DetailsPage):
self.location('/moncompte/index.php?page=suiviconso') self.location('/moncompte/index.php?page=suiviconso')
return self.page.date_bills() return self.page.date_bills(subscription)
def get_bill(self, id): def get_bill(self, id):
assert isinstance(id, basestring) assert isinstance(id, basestring)

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
from datetime import datetime, date, time from datetime import datetime, date, time
from decimal import Decimal from decimal import Decimal
@ -41,7 +42,7 @@ class DetailsPage(BasePage):
def on_loaded(self): def on_loaded(self):
self.details = {} self.details = {}
self.datebills = [] self.datebills = {}
for div in self.document.xpath('//div[@class="infosLigne pointer"]'): for div in self.document.xpath('//div[@class="infosLigne pointer"]'):
phonenumber = div.text phonenumber = div.text
phonenumber = phonenumber.split("-")[-1].strip() phonenumber = phonenumber.split("-")[-1].strip()
@ -60,23 +61,26 @@ class DetailsPage(BasePage):
divint = div.xpath('div[@class="international hide"]')[0] divint = div.xpath('div[@class="international hide"]')[0]
self.parse_div(divint, u"Appels émis : %s | Appels reçus : %s", num, True) self.parse_div(divint, u"Appels émis : %s | Appels reçus : %s", num, True)
divbill = self.document.xpath('//div[@class="facture"]')[0] for divbill in self.document.xpath('//div[@class="facture"]'):
for trbill in divbill.xpath('table/tr'): for trbill in divbill.xpath('table/tr'):
mydate = unicode(trbill.find('td').text.split(":")[1].strip()) mydate = unicode(trbill.find('td').text.split(":")[1].strip())
bill = Bill() for alink in trbill.xpath('td/a'):
bill.label = unicode(mydate) bill = Bill()
billid = mydate.replace('-', '') bill.label = unicode(mydate)
billid = billid[4:8] + billid[2:4] + billid[0:2] billid = mydate.replace('-', '')
bill.id = phonenumber + "." + billid billid = billid[4:8] + billid[2:4] + billid[0:2]
bill.date = date(*reversed([int(x) for x in mydate.split("-")])) bill.id = billid
alink = trbill.find('td/a') bill.date = date(*reversed([int(x) for x in mydate.split("-")]))
if alink.attrib.get("class") == "linkModal tips": bill.format = u"pdf"
bill.format = u'html' bill._url = alink.attrib.get('href')
bill._url = alink.attrib.get('data-link') if "pdfrecap" in alink.attrib.get('href'):
else: bill.id = "recap-" + bill.id
bill.format = u"pdf" localid = re.search('&l=(?P<id>\d*)&id',
bill._url = alink.attrib.get('href') alink.attrib.get('href')).group('id')
self.datebills.append(bill) if not self.datebills.has_key(localid):
self.datebills[localid] = []
self.datebills[localid].append(bill)
def parse_div(self, divglobal, string, num, inter=False): def parse_div(self, divglobal, string, num, inter=False):
divs = divglobal.xpath('div[@class="detail"]') divs = divglobal.xpath('div[@class="detail"]')
@ -120,8 +124,10 @@ class DetailsPage(BasePage):
detail.id = subscription.id + detail.id detail.id = subscription.id + detail.id
yield detail yield detail
def date_bills(self): def date_bills(self, subscription):
return self.datebills for bill in self.datebills[subscription._login]:
bill.id = subscription.id + '.' + bill.id
yield bill
def get_renew_date(self, subscription): def get_renew_date(self, subscription):
login = subscription._login login = subscription._login