Commit 4fda0965 authored by Vincent A's avatar Vincent A

[bouygues] implement CapMessagesPost

parent 58bd6532
......@@ -30,6 +30,7 @@ from weboob.tools.compat import urlparse, parse_qsl
from .pages import (
LoginPage, ForgottenPasswordPage, AppConfigPage, SubscriberPage, SubscriptionPage, SubscriptionDetail, DocumentPage,
DocumentDownloadPage, DocumentFilePage,
SendSMSPage,
)
......@@ -57,6 +58,9 @@ class BouyguesBrowser(LoginBrowser):
documents_page = URL(r'/comptes-facturation/(?P<id_account>\d+)/factures(\?|$)', DocumentPage)
document_download_page = URL(r'/comptes-facturation/(?P<id_account>\d+)/factures/.*(\?|$)', DocumentDownloadPage)
send_sms = URL(r'https://www.secure.bbox.bouyguestelecom.fr/services/SMSIHD/sendSMS.phtml', SendSMSPage)
confirm_sms = URL(r'https://www.secure.bbox.bouyguestelecom.fr/services/SMSIHD/resultSendSMS.phtml')
def __init__(self, username, password, lastname, *args, **kwargs):
super(BouyguesBrowser, self).__init__(username, password, *args, **kwargs)
self.lastname = lastname
......@@ -130,3 +134,9 @@ class BouyguesBrowser(LoginBrowser):
def download_document(self, document):
if document.url:
return self.location(document.url, headers=self.headers).content
@need_login
def post_message(self, receivers, content):
self.send_sms.go()
self.page.post_message(receivers, content)
self.confirm_sms.open() # no params: stateful?!
......@@ -19,10 +19,10 @@
from __future__ import unicode_literals
from weboob.tools.backend import Module, BackendConfig
from weboob.capabilities.base import find_object
from weboob.capabilities.bill import CapDocument, Document, SubscriptionNotFound, Subscription, DocumentNotFound
from weboob.capabilities.messages import CapMessagesPost
from weboob.tools.value import Value, ValueBackendPassword
from .browser import BouyguesBrowser
......@@ -31,7 +31,7 @@ from .browser import BouyguesBrowser
__all__ = ['BouyguesModule']
class BouyguesModule(Module, CapDocument):
class BouyguesModule(Module, CapDocument, CapMessagesPost):
NAME = 'bouygues'
DESCRIPTION = 'Bouygues Télécom'
MAINTAINER = 'Florian Duguet'
......@@ -66,3 +66,10 @@ class BouyguesModule(Module, CapDocument):
if not isinstance(document, Document):
document = self.get_document(document)
return self.browser.download_document(document)
def post_message(self, message):
receivers = message.receivers
if not receivers:
assert message.thread
receivers = [message.thread.id]
self.browser.post_message(receivers, message.content)
......@@ -144,3 +144,18 @@ class DocumentFilePage(LoggedPage, RawPage):
# since url of this file is almost the same than url of DocumentDownloadPage (which is a JsonPage)
# we have to define it to avoid mismatching
pass
class SendSMSPage(LoggedPage, HTMLPage):
def post_message(self, receivers, content):
form = self.get_form(name='formSMS')
quota_text = CleanText('.//strong')(form.el)
quota = int(re.search(r'(\d+) SMS gratuit', quota_text)[1])
self.logger.info('quota: %d messages left', quota)
if not quota:
raise Exception('quota exceeded')
form['fieldMsisdn'] = ';'.join(receivers)
form['fieldMessage'] = content
form.submit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment