support repositories to manage backends (closes #747)
This commit is contained in:
parent
ef16a5b726
commit
14a7a1d362
410 changed files with 1079 additions and 297 deletions
3
modules/sfr/__init__.py
Normal file
3
modules/sfr/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from .backend import SfrBackend
|
||||
|
||||
__all__ = ['SfrBackend']
|
||||
60
modules/sfr/backend.py
Normal file
60
modules/sfr/backend.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# -*- 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 __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import CantSendMessage, ICapMessages, ICapMessagesPost
|
||||
from weboob.capabilities.account import ICapAccount, StatusField
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import Value, ValueBackendPassword
|
||||
|
||||
from .browser import SfrBrowser
|
||||
|
||||
|
||||
__all__ = ['SfrBackend']
|
||||
|
||||
|
||||
class SfrBackend(BaseBackend, ICapAccount, ICapMessages, ICapMessagesPost):
|
||||
NAME = 'sfr'
|
||||
MAINTAINER = 'Christophe Benz'
|
||||
EMAIL = 'christophe.benz@gmail.com'
|
||||
VERSION = '0.a'
|
||||
DESCRIPTION = 'SFR french mobile phone provider'
|
||||
LICENSE = 'AGPLv3+'
|
||||
CONFIG = BackendConfig(Value('login', label='Login'),
|
||||
ValueBackendPassword('password', label='Password'))
|
||||
BROWSER = SfrBrowser
|
||||
ACCOUNT_REGISTER_PROPERTIES = None
|
||||
|
||||
def create_default_browser(self):
|
||||
return self.create_browser(self.config['login'].get(), self.config['password'].get())
|
||||
|
||||
# ICapMessagesPost methods
|
||||
|
||||
def get_account_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.')
|
||||
with self.browser:
|
||||
self.browser.post_message(message)
|
||||
66
modules/sfr/browser.py
Normal file
66
modules/sfr/browser.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# -*- 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 urllib
|
||||
|
||||
from .pages.compose import ClosePage, ComposePage, ConfirmPage, SentPage
|
||||
from .pages.login import LoginPage
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
|
||||
|
||||
__all__ = ['SfrBrowser']
|
||||
|
||||
|
||||
class SfrBrowser(BaseBrowser):
|
||||
DOMAIN = 'www.sfr.fr'
|
||||
PAGES = {
|
||||
'http://messagerie-.+.sfr.fr/webmail/close_xms_tab.html': ClosePage,
|
||||
'http://www.sfr.fr/xmscomposer/index.html\?todo=compose': ComposePage,
|
||||
'http://www.sfr.fr/xmscomposer/mc/envoyer-texto-mms/confirm.html': ConfirmPage,
|
||||
'https://www.sfr.fr/cas/login\?service=.*': LoginPage,
|
||||
'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')
|
||||
|
||||
def is_logged(self):
|
||||
return 'loginForm' not in [form.name for form in self.forms()]
|
||||
|
||||
def login(self):
|
||||
service_url = 'http://www.sfr.fr/xmscomposer/j_spring_cas_security_check'
|
||||
self.location('https://www.sfr.fr/cas/login?service=%s' % urllib.quote_plus(service_url), no_login=True)
|
||||
self.page.login(self.username, self.password)
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
def post_message(self, message):
|
||||
if not self.is_on_page(ComposePage):
|
||||
self.home()
|
||||
self.page.post_message(message)
|
||||
if self.is_on_page(ConfirmPage):
|
||||
self.page.confirm()
|
||||
assert self.is_on_page(ClosePage) or self.is_on_page(SentPage)
|
||||
BIN
modules/sfr/favicon.png
Normal file
BIN
modules/sfr/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
0
modules/sfr/pages/__init__.py
Normal file
0
modules/sfr/pages/__init__.py
Normal file
60
modules/sfr/pages/compose.py
Normal file
60
modules/sfr/pages/compose.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# -*- 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.tools.browser import BasePage
|
||||
|
||||
|
||||
|
||||
__all__ = ['ClosePage', 'ComposePage', 'ConfirmPage', 'SentPage']
|
||||
|
||||
|
||||
class ClosePage(BasePage):
|
||||
pass
|
||||
|
||||
|
||||
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 = self.parser.select(self.document.getroot(), '#smsReminder', 1).text.strip()
|
||||
return remaining_regex.match(text).groupdict().get('nb')
|
||||
|
||||
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['msisdns'] = receiver
|
||||
self.browser['textMessage'] = message.content.encode('utf-8')
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class ConfirmPage(BasePage):
|
||||
def confirm(self):
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class SentPage(BasePage):
|
||||
pass
|
||||
33
modules/sfr/pages/login.py
Normal file
33
modules/sfr/pages/login.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# -*- 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.tools.browser import BasePage
|
||||
|
||||
|
||||
__all__ = ['LoginPage']
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def login(self, login, password):
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser['username'] = login
|
||||
self.browser['password'] = password
|
||||
self.browser['remember-me'] = ['on']
|
||||
self.browser.submit()
|
||||
27
modules/sfr/test.py
Normal file
27
modules/sfr/test.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# -*- 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.tools.test import BackendTest
|
||||
|
||||
class SFRTest(BackendTest):
|
||||
BACKEND = 'sfr'
|
||||
|
||||
def test_sfr(self):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue