implement StatusField in sfr backend
This commit is contained in:
parent
27e337d520
commit
b24b40ac98
4 changed files with 34 additions and 3 deletions
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import CantSendMessage, ICapMessagesPost
|
||||
from weboob.capabilities.messages import CantSendMessage, ICapMessagesPost, StatusField
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
|
|
@ -44,7 +44,13 @@ class SfrBackend(BaseBackend, ICapMessagesPost):
|
|||
|
||||
# ICapMessagesPost methods
|
||||
|
||||
def get_status(self):
|
||||
with self.browser:
|
||||
return (StatusField('nb_remaining_free_sms', 'Number of remaining free SMS',
|
||||
self.browser.get_nb_remaining_free_sms()),)
|
||||
|
||||
def post_message(self, message):
|
||||
if not message.content.strip():
|
||||
raise CantSendMessage(u'Message content is empty.')
|
||||
self.browser.post_message(message)
|
||||
with self.browser:
|
||||
self.browser.post_message(message)
|
||||
|
|
@ -37,6 +37,11 @@ class SfrBrowser(BaseBrowser):
|
|||
'http://www.sfr.fr/xmscomposer/mc/envoyer-texto-mms/send.html': SentPage,
|
||||
}
|
||||
|
||||
def get_nb_remaining_free_sms(self):
|
||||
if not self.is_on_page(ComposePage):
|
||||
self.home()
|
||||
return self.page.get_nb_remaining_free_sms()
|
||||
|
||||
def home(self):
|
||||
self.location('http://www.sfr.fr/xmscomposer/index.html?todo=compose')
|
||||
|
||||
|
|
@ -52,7 +57,7 @@ class SfrBrowser(BaseBrowser):
|
|||
|
||||
def post_message(self, message):
|
||||
if not self.is_on_page(ComposePage):
|
||||
self.location('http://www.sfr.fr/xmscomposer/index.html\?todo=compose')
|
||||
self.home()
|
||||
self.page.post_message(message)
|
||||
if self.is_on_page(ConfirmPage):
|
||||
self.page.confirm()
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import re
|
|||
|
||||
from weboob.capabilities.messages import CantSendMessage
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.parsers.lxmlparser import select, SelectElementException
|
||||
|
||||
|
||||
__all__ = ['ClosePage', 'ComposePage', 'ConfirmPage', 'SentPage']
|
||||
|
|
@ -32,6 +33,11 @@ class ClosePage(BasePage):
|
|||
class ComposePage(BasePage):
|
||||
phone_regex = re.compile('^(\+33|0033|0)(6|7)(\d{8})$')
|
||||
|
||||
def get_nb_remaining_free_sms(self):
|
||||
remaining_regex = re.compile(u'Il vous reste (?P<nb>.+) Texto gratuits vers les numéros SFR à envoyer aujourd\'hui')
|
||||
text = select(self.document.getroot(), '#smsReminder', 1).text.strip()
|
||||
return remaining_regex.match(text).groupdict().get('nb')
|
||||
|
||||
def post_message(self, message):
|
||||
receiver_list = [receiver.strip() for receiver in message.receiver.split(',')]
|
||||
for receiver in receiver_list:
|
||||
|
|
|
|||
|
|
@ -116,6 +116,14 @@ class Thread(CapBaseObject):
|
|||
for m in self._iter_all_messages(child):
|
||||
yield m
|
||||
|
||||
|
||||
class StatusField(object):
|
||||
def __init__(self, key, label, value):
|
||||
self.key = key
|
||||
self.label = label
|
||||
self.value = value
|
||||
|
||||
|
||||
class ICapMessages(IBaseCap):
|
||||
def iter_threads(self):
|
||||
"""
|
||||
|
|
@ -154,6 +162,12 @@ class CantSendMessage(Exception):
|
|||
pass
|
||||
|
||||
class ICapMessagesPost(IBaseCap):
|
||||
def get_status(self):
|
||||
"""
|
||||
Get a list of fields
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def post_message(self, message):
|
||||
"""
|
||||
Post a message.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue