Fix after site changes and better handle of login
This commit is contained in:
parent
4ec183aadf
commit
e59bcdd749
2 changed files with 28 additions and 23 deletions
18
modules/ameli/browser.py
Normal file → Executable file
18
modules/ameli/browser.py
Normal file → Executable file
|
|
@ -47,31 +47,35 @@ class AmeliBrowser(BaseBrowser):
|
||||||
is_logging = False
|
is_logging = False
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
if not self.is_logged():
|
self.logger.debug('call Browser.home')
|
||||||
self.login()
|
|
||||||
self.location(self.homep)
|
self.location(self.homep)
|
||||||
|
if ((not self.is_logged()) and (not self.is_logging)):
|
||||||
|
self.login()
|
||||||
|
|
||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
logged = self.page and self.page.is_logged() or self.is_logging
|
self.logger.debug('call Browser.is_logged')
|
||||||
self.logger.debug('logged: %s' % (logged))
|
return self.page.is_logged()
|
||||||
return logged
|
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
|
self.logger.debug('call Browser.login')
|
||||||
# Do we really need to login?
|
# Do we really need to login?
|
||||||
if self.is_logged():
|
if self.is_logged():
|
||||||
self.logger.debug('Already logged in')
|
self.logger.debug('Already logged in')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.is_logging:
|
||||||
|
return
|
||||||
|
|
||||||
self.is_logging = True
|
self.is_logging = True
|
||||||
|
|
||||||
self.location(self.loginp)
|
self.location(self.loginp)
|
||||||
self.page.login(self.username, self.password)
|
self.page.login(self.username, self.password)
|
||||||
|
|
||||||
self.is_logging = False
|
|
||||||
|
|
||||||
if not self.is_logged():
|
if not self.is_logged():
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
|
self.is_logging = False
|
||||||
|
|
||||||
def iter_subscription_list(self):
|
def iter_subscription_list(self):
|
||||||
if not self.is_on_page(AccountPage):
|
if not self.is_on_page(AccountPage):
|
||||||
self.location(self.accountp)
|
self.location(self.accountp)
|
||||||
|
|
|
||||||
31
modules/ameli/pages.py
Normal file → Executable file
31
modules/ameli/pages.py
Normal file → Executable file
|
|
@ -22,7 +22,7 @@ from datetime import datetime
|
||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage,BrokenPageError
|
||||||
from weboob.capabilities.bill import Subscription, Detail, Bill
|
from weboob.capabilities.bill import Subscription, Detail, Bill
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,11 +31,16 @@ __all__ = ['AmeliBasePage', 'LoginPage', 'HomePage', 'AccountPage', 'LastPayment
|
||||||
# Ugly array to avoid the use of french locale
|
# 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']
|
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(BasePage):
|
class AmeliBasePage(BasePage):
|
||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
return len(self.document.xpath('//a[@id="logout"]')) > 0
|
try:
|
||||||
|
self.parser.select(self.document.getroot(), 'a.logout', 1)
|
||||||
|
except BrokenPageError:
|
||||||
|
logged = False
|
||||||
|
else:
|
||||||
|
logged = True
|
||||||
|
self.logger.debug('logged: %s' % (logged))
|
||||||
|
return logged
|
||||||
|
|
||||||
class LoginPage(AmeliBasePage):
|
class LoginPage(AmeliBasePage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
|
|
@ -44,22 +49,18 @@ class LoginPage(AmeliBasePage):
|
||||||
self.browser["connexioncompte_2codeConfidentiel"] = password.encode('utf8')
|
self.browser["connexioncompte_2codeConfidentiel"] = password.encode('utf8')
|
||||||
self.browser.submit()
|
self.browser.submit()
|
||||||
|
|
||||||
|
|
||||||
class HomePage(AmeliBasePage):
|
class HomePage(AmeliBasePage):
|
||||||
def on_loaded(self):
|
pass
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AccountPage(AmeliBasePage):
|
class AccountPage(AmeliBasePage):
|
||||||
|
|
||||||
def iter_subscription_list(self):
|
def iter_subscription_list(self):
|
||||||
idents = self.document.xpath('//div[contains(@class, "blocfond")]')
|
idents = self.document.xpath('//div[contains(@class, "blocfond")]')
|
||||||
enfants = 0
|
enfants = 0
|
||||||
for ident in idents:
|
for ident in idents:
|
||||||
if len(ident.xpath('.//h4')) == 0:
|
if len(ident.xpath('.//h3')) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = self.parser.tocleanstring(ident.xpath('.//h4')[0])
|
name = self.parser.tocleanstring(ident.xpath('.//h3')[0])
|
||||||
lis = ident.xpath('.//li')
|
lis = ident.xpath('.//li')
|
||||||
if len(lis) > 3:
|
if len(lis) > 3:
|
||||||
number = re.sub('[^\d]+', '', ident.xpath('.//li')[3].text)
|
number = re.sub('[^\d]+', '', ident.xpath('.//li')[3].text)
|
||||||
|
|
@ -75,7 +76,7 @@ class AccountPage(AmeliBasePage):
|
||||||
|
|
||||||
class LastPaymentsPage(AmeliBasePage):
|
class LastPaymentsPage(AmeliBasePage):
|
||||||
def iter_last_payments(self):
|
def iter_last_payments(self):
|
||||||
list_table = self.document.xpath('//table[@id="ligneTabDerniersPaiements"]')
|
list_table = self.document.xpath('//table[@id="tabDerniersPaiements"]')
|
||||||
if len(list_table) > 0:
|
if len(list_table) > 0:
|
||||||
table = list_table[0].xpath('.//tr')
|
table = list_table[0].xpath('.//tr')
|
||||||
for tr in table:
|
for tr in table:
|
||||||
|
|
@ -91,14 +92,14 @@ class PaymentDetailsPage(AmeliBasePage):
|
||||||
idx = 0
|
idx = 0
|
||||||
else:
|
else:
|
||||||
idx = sub._id.replace('AFFILIE', '')
|
idx = sub._id.replace('AFFILIE', '')
|
||||||
if len(self.document.xpath('//div[@class="centrepage"]/h3')) > idx or self.document.xpath('//table[@id="DetailPaiement3"]') > idx:
|
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"]/h3')[idx].text.strip()
|
id_str = self.document.xpath('//div[@class="centrepage"]/h2')[idx].text.strip()
|
||||||
m = re.match('.*le (.*) pour un montant de.*', id_str)
|
m = re.match('.*le (.*) pour un montant de.*', id_str)
|
||||||
if m:
|
if m:
|
||||||
id_str = m.group(1)
|
id_str = m.group(1)
|
||||||
id_date = datetime.strptime(id_str, '%d/%m/%Y').date()
|
id_date = datetime.strptime(id_str, '%d/%m/%Y').date()
|
||||||
id = sub._id + "." + datetime.strftime(id_date, "%Y%m%d")
|
id = sub._id + "." + datetime.strftime(id_date, "%Y%m%d")
|
||||||
table = self.document.xpath('//table[@id="DetailPaiement3"]')[idx].xpath('.//tr')
|
table = self.document.xpath('//table[@class="tableau"]')[idx].xpath('.//tr')
|
||||||
line = 1
|
line = 1
|
||||||
last_date = None
|
last_date = None
|
||||||
for tr in table:
|
for tr in table:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue