[bouygues] rewrite backend using browser2 (fix #1970 and #1978)

This commit is contained in:
Bezleputh 2015-06-17 17:49:21 +02:00
commit e8e7e60a50
7 changed files with 93 additions and 126 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Christophe Benz
# Copyright(C) 2010-2015 Bezleputh
#
# This file is part of weboob.
#
@ -17,46 +17,48 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.browser import LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword
from .pages import LoginPage, LoginSuccess, SendSMSPage, SendSMSErrorPage
from .pages.compose import ComposeFrame, ComposePage, ConfirmPage, SentPage
from .pages.login import LoginPage, LoginSASPage
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
from weboob.capabilities.messages import CantSendMessage
__all__ = ['BouyguesBrowser']
class BouyguesBrowser(Browser):
DOMAIN = 'www.bouyguestelecom.fr'
PAGES = {
'http://www.espaceclient.bouyguestelecom.fr/ECF/jsf/client/envoiSMS/viewEnvoiSMS.jsf': ComposePage,
'http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/sendSMS.phtml': ComposeFrame,
'http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/confirmSendSMS.phtml': ConfirmPage,
'https://www.espaceclient.bouyguestelecom.fr/ECF/jsf/submitLogin.jsf': LoginPage,
'https://www.espaceclient.bouyguestelecom.fr/ECF/SasUnifie': LoginSASPage,
'http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/resultSendSMS.phtml': SentPage,
}
class BouyguesBrowser(LoginBrowser):
BASEURL = 'https://www.mon-compte.bouyguestelecom.fr/'
TIMEOUT = 20
def home(self):
self.location('http://www.espaceclient.bouyguestelecom.fr/ECF/jsf/client/envoiSMS/viewEnvoiSMS.jsf')
home = URL('http://www.bouyguestelecom.fr/mon-compte/', LoginSuccess)
login = URL('cas/login', LoginPage)
def is_logged(self):
return 'code' not in [form.name for form in self.forms()]
sms_page = URL('http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/sendSMS.phtml',
'http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/confirmSendSMS.phtml',
SendSMSPage)
def login(self):
self.location('https://www.espaceclient.bouyguestelecom.fr/ECF/jsf/submitLogin.jsf', no_login=True)
self.page.login(self.username, self.password)
assert self.is_on_page(LoginSASPage)
self.page.login()
if not self.is_logged():
raise BrowserIncorrectPassword()
confirm = URL('http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/resultSendSMS.phtml')
sms_error_page = URL('http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/SMS_erreur.phtml',
SendSMSErrorPage)
def do_login(self):
self.login.go().login(self.username, self.password)
if not self.home.is_here():
raise BrowserIncorrectPassword
@need_login
def post_message(self, message):
if not self.is_on_page(ComposeFrame):
self.home()
self.location('http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/sendSMS.phtml')
self.page.post_message(message)
assert self.is_on_page(ConfirmPage)
self.page.confirm()
assert self.is_on_page(SentPage)
self.sms_page.go()
if self.sms_error_page.is_here():
raise CantSendMessage(self.page.get_error_message())
receivers = ";".join(list(message.receivers)) if message.receivers else self.username
self.page.send_sms(message, receivers)
if self.sms_error_page.is_here():
raise CantSendMessage(self.page.get_error_message())
self.confirm.open()

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Christophe Benz
# Copyright(C) 2010-2015 Bezleputh
#
# This file is part of weboob.
#
@ -30,15 +30,14 @@ __all__ = ['BouyguesModule']
class BouyguesModule(Module, CapMessages, CapMessagesPost):
NAME = 'bouygues'
MAINTAINER = u'Christophe Benz'
EMAIL = 'christophe.benz@gmail.com'
MAINTAINER = u'Bezleputh'
EMAIL = 'carton_ben@yahoo.fr'
VERSION = '1.1'
DESCRIPTION = u'Bouygues Télécom French mobile phone provider'
LICENSE = 'AGPLv3+'
CONFIG = BackendConfig(Value('login', label='Login'),
CONFIG = BackendConfig(Value('login', label='Login/Phone number'),
ValueBackendPassword('password', label='Password'))
BROWSER = BouyguesBrowser
ACCOUNT_REGISTER_PROPERTIES = None
def create_default_browser(self):
return self.create_browser(self.config['login'].get(), self.config['password'].get())
@ -46,5 +45,4 @@ class BouyguesModule(Module, CapMessages, CapMessagesPost):
def post_message(self, message):
if not message.content.strip():
raise CantSendMessage(u'Message content is empty.')
with self.browser:
self.browser.post_message(message)
self.browser.post_message(message)

52
modules/bouygues/pages.py Normal file
View file

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2015 Bezleputh
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.messages import CantSendMessage
from weboob.browser.pages import HTMLPage, LoggedPage
from weboob.browser.filters.standard import CleanDecimal, CleanText, Regexp
class LoginPage(HTMLPage):
def login(self, login, password):
form = self.get_form('//form[@id="log_data"]')
form['username'] = login
form['password'] = password
form.submit()
class LoginSuccess(HTMLPage, LoggedPage):
pass
class SendSMSPage(HTMLPage):
def send_sms(self, message, receivers):
sms_number = CleanDecimal(Regexp(CleanText('//span[@class="txt12-o"][1]/strong'), '(\d*) SMS.*'))(self.doc)
if sms_number == 0:
msg = CleanText('//span[@class="txt12-o"][1]')(self.doc)
raise CantSendMessage(msg)
form = self.get_form('//form[@name="formSMS"]')
form["fieldMsisdn"] = receivers
form["fieldMessage"] = message.content
form.submit()
class SendSMSErrorPage(HTMLPage):
def get_error_message(self):
return CleanText('//span[@class="txt12-o"][1]')(self.doc)

View file

@ -1,50 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Christophe Benz
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
from weboob.capabilities.messages import CantSendMessage
from weboob.deprecated.browser import Page
class ComposeFrame(Page):
phone_regex = re.compile('^(\+33|0033|0)(6|7)(\d{8})$')
def post_message(self, message):
receiver = message.thread.id
if self.phone_regex.match(receiver) is None:
raise CantSendMessage(u'Invalid receiver: %s' % receiver)
self.browser.select_form(nr=0)
self.browser['fieldMsisdn'] = receiver
self.browser['fieldMessage'] = message.content.encode('utf-8')
self.browser.submit()
class ComposePage(Page):
pass
class ConfirmPage(Page):
def confirm(self):
self.browser.location('http://www.mobile.service.bbox.bouyguestelecom.fr/services/SMSIHD/resultSendSMS.phtml')
class SentPage(Page):
pass

View file

@ -1,35 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Christophe Benz
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.deprecated.browser import Page
class LoginPage(Page):
def login(self, login, password):
self.browser.select_form(name='code')
self.browser['j_username'] = login
self.browser['j_password'] = password
self.browser.submit()
class LoginSASPage(Page):
def login(self):
self.browser.select_form(name='redirect')
self.browser.submit()

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Christophe Benz
# Copyright(C) 2010-2015 Bezleputh
#
# This file is part of weboob.
#