[Ameli]&[Amelipro] Update after sites changes, and upgrade to new browser

This commit is contained in:
Kitof 2013-12-17 22:22:52 +01:00 committed by Romain Bignon
commit 10c5abc3d4
7 changed files with 251 additions and 229 deletions

View file

@ -22,53 +22,48 @@ from datetime import datetime
import re
import urllib
from decimal import Decimal
from weboob.deprecated.browser import Page, BrokenPageError
from weboob.browser.pages import HTMLPage
from weboob.capabilities.bill import Subscription, Detail, Bill
from weboob.browser.filters.standard import CleanText
# Ugly array to avoid the use of french locale
FRENCH_MONTHS = [u'janvier', u'février', u'mars', u'avril', u'mai', u'juin', u'juillet', u'août', u'septembre', u'octobre', u'novembre', u'décembre']
class AmeliBasePage(Page):
class AmeliBasePage(HTMLPage):
def is_logged(self):
try:
self.parser.select(self.document.getroot(), 'a.logout', 1)
except BrokenPageError:
logged = False
else:
if self.doc.xpath('//a[@id="id_lien_deco"]'):
logged = True
else:
logged = False
self.logger.debug('logged: %s' % (logged))
return logged
class LoginPage(AmeliBasePage):
def login(self, login, password):
self.browser.select_form('connexionCompteForm')
self.browser["connexioncompte_2numSecuriteSociale"] = login.encode('utf8')
self.browser["connexioncompte_2codeConfidentiel"] = password.encode('utf8')
self.browser.submit()
form = self.get_form('//form[@name="connexionCompteForm"]')
form['connexioncompte_2numSecuriteSociale'] = login.encode('utf8')
form['connexioncompte_2codeConfidentiel'] = password.encode('utf8')
form.submit()
class HomePage(AmeliBasePage):
pass
class AccountPage(AmeliBasePage):
def iter_subscription_list(self):
idents = self.document.xpath('//div[contains(@class, "blocfond")]')
enfants = 0
for ident in idents:
if len(ident.xpath('.//h3')) == 0:
continue
name = CleanText('//div[@id="bloc_contenu_masituation"]/h3', replace=[('Titulaire du compte : ', '')])(self.doc)
number = re.sub('[^\d]+', '', self.doc.xpath('//div[@id="bloc_contenu_masituation"]/ul/li')[2].text)
sub = Subscription(number)
sub._id = number
sub.label = unicode(name)
sub.subscriber = unicode(name)
yield sub
name = self.parser.tocleanstring(ident.xpath('.//h3')[0])
lis = ident.xpath('.//li')
if len(lis) > 3:
number = re.sub('[^\d]+', '', ident.xpath('.//li')[3].text)
else:
enfants = enfants + 1
number = "AFFILIE" + str(enfants)
nb_childs = 0
childs = self.doc.xpath('//div[@class="bloc_infos"]')
for child in childs:
name = CleanText('.//h3[1]')(child)
nb_childs = nb_childs + 1
number = "AFFILIE" + str(nb_childs)
sub = Subscription(number)
sub._id = number
sub.label = unicode(name)
@ -78,14 +73,14 @@ class AccountPage(AmeliBasePage):
class LastPaymentsPage(AmeliBasePage):
def iter_last_payments(self):
list_table = self.document.xpath('//table[@id="tabDerniersPaiements"]')
list_table = self.doc.xpath('//table[@id="tabDerniersPaiements"]')
if len(list_table) > 0:
table = list_table[0].xpath('.//tr')
for tr in table:
list_a = tr.xpath('.//a')
if len(list_a) == 0:
continue
yield list_a[0].attrib.get('href')
yield list_a[0].attrib.get('href').replace(':443','')
class PaymentDetailsPage(AmeliBasePage):
@ -94,39 +89,86 @@ class PaymentDetailsPage(AmeliBasePage):
idx = 0
else:
idx = sub._id.replace('AFFILIE', '')
if len(self.document.xpath('//div[@class="centrepage"]/h2')) > idx or self.document.xpath('//table[@id="DetailPaiement3"]') > idx:
id_str = self.document.xpath('//div[@class="centrepage"]/h2')[idx].text.strip()
if len(self.doc.xpath('//div[@class="centrepage"]/h2')) > idx or self.doc.xpath('//table[@id="DetailPaiement3"]') > idx:
id_str = self.doc.xpath('//div[@class="centrepage"]/h2')[idx].text.strip()
m = re.match('.*le (.*) pour un montant de.*', id_str)
if m:
id_str = m.group(1)
id_date = datetime.strptime(id_str, '%d/%m/%Y').date()
id = sub._id + "." + datetime.strftime(id_date, "%Y%m%d")
table = self.document.xpath('//table[@class="tableau"]')[idx].xpath('.//tr')
table = self.doc.xpath('//table[@class="tableau"]')[idx].xpath('.//tr')
line = 1
last_date = None
for tr in table:
tds = tr.xpath('.//td')
if len(tds) == 0:
continue
date_str = tds[0].text
det = Detail()
det.id = id + "." + str(line)
det.label = unicode(tds[1].text.strip())
if date_str is None or date_str == '':
det.infos = u''
det.datetime = last_date
else:
det.infos = u'Payé ' + unicode(re.sub('[^\d,-]+', '', tds[2].text)) + u'€ / Base ' + unicode(re.sub('[^\d,-]+', '', tds[3].text)) + u'€ / Taux ' + unicode(re.sub('[^\d,-]+', '', tds[4].text)) + '%'
det.datetime = datetime.strptime(date_str, '%d/%m/%Y').date()
last_date = det.datetime
det.price = Decimal(re.sub('[^\d,-]+', '', tds[5].text).replace(',', '.'))
if len(tds) == 5:
date_str = tds[0].text
det.id = id + "." + str(line)
det.label = unicode(tds[1].text.strip())
jours = tds[2].text
if jours is None:
jours = '0'
montant = tds[3].text
if montant is None:
montant = '0'
price = tds[4].text
if price is None:
price = '0'
if date_str is None or date_str == '':
det.infos = u''
det.datetime = last_date
else:
det.infos = date_str + u' (' + unicode(re.sub('[^\d,-]+', '', jours)) + u'j) * ' + unicode(re.sub('[^\d,-]+', '', montant)) + u''
det.datetime = datetime.strptime(date_str.split(' ')[3], '%d/%m/%Y').date()
last_date = det.datetime
det.price = Decimal(re.sub('[^\d,-]+', '', price).replace(',', '.'))
if len(tds) == 6:
date_str = tds[0].text
det.id = id + "." + str(line)
det.label = unicode(tds[1].text.strip())
paye = tds[2].text
if paye is None:
paye = '0'
base = tds[3].text
if base is None:
base = '0'
taux = tds[4].text
if taux is None:
taux = '0'
price = tds[5].text
if price is None:
price = '0'
if date_str is None or date_str == '':
det.infos = u''
det.datetime = last_date
else:
det.infos = u'Payé ' + unicode(re.sub('[^\d,-]+', '', paye)) + u'€ / Base ' + unicode(re.sub('[^\d,-]+', '', base)) + u'€ / Taux ' + unicode(re.sub('[^\d,-]+', '', taux)) + '%'
det.datetime = datetime.strptime(date_str, '%d/%m/%Y').date()
last_date = det.datetime
det.price = Decimal(re.sub('[^\d,-]+', '', price).replace(',', '.'))
line = line + 1
yield det
class BillsPage(AmeliBasePage):
def iter_bills(self, sub):
table = self.document.xpath('//table[@id="tableauDecompte"]')[0].xpath('.//tr')
table = self.doc.xpath('//table[@id="relevesMensuels"]')[0].xpath('.//tr')
for tr in table:
list_tds = tr.xpath('.//td')
if len(list_tds) == 0:
@ -137,15 +179,14 @@ class BillsPage(AmeliBasePage):
amount = list_tds[1].text
if amount is None:
continue
amount = re.sub(' euros', '', amount)
amount = re.sub('[^\d,-]+', '', amount)
bil = Bill()
bil.id = sub._id + "." + date.strftime("%Y%m")
bil.date = date
bil.label = u''+amount.strip()
bil.price = Decimal('-'+amount.strip().replace(',','.'))
bil.format = u'pdf'
filedate = date.strftime("%m%Y")
bil._url = '/PortailAS/PDFServletReleveMensuel.dopdf'
bil._args = {'PDF.moisRecherche': filedate}
bil.label = date.strftime("%Y%m%d")
bil._url = '/PortailAS/PDFServletReleveMensuel.dopdf?PDF.moisRecherche='+date.strftime("%m%Y")
yield bil
def get_bill(self, bill):