[okc] Initial message posting
This commit is contained in:
parent
cba809a8d0
commit
5b508ca340
3 changed files with 18 additions and 23 deletions
|
|
@ -42,7 +42,6 @@ from .browser import OkCBrowser
|
|||
|
||||
__all__ = ['OkCBackend']
|
||||
|
||||
|
||||
def parse_dt(s):
|
||||
now = datetime.datetime.now()
|
||||
if u'–' in s:
|
||||
|
|
@ -62,8 +61,7 @@ def parse_dt(s):
|
|||
d = _parse_dt(s)
|
||||
return local2utc(d)
|
||||
|
||||
class OkCBackend(BaseBackend, ICapMessages, ICapContact):
|
||||
#, ICapMessagesPost, ICapContact):
|
||||
class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost):
|
||||
NAME = 'okc'
|
||||
MAINTAINER = 'Roger Philibert'
|
||||
EMAIL = 'roger.philibert@gmail.com'
|
||||
|
|
@ -223,9 +221,9 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact):
|
|||
|
||||
# ---- ICapMessagesPost methods ---------------------
|
||||
|
||||
#def post_message(self, message):
|
||||
# with self.browser:
|
||||
# self.browser.post_mail(message.thread.id, message.content)
|
||||
def post_message(self, message):
|
||||
with self.browser:
|
||||
self.browser.post_mail(message.thread.id, message.content)
|
||||
|
||||
# ---- ICapContact methods ---------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ except ImportError:
|
|||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserUnavailable
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
||||
from .pages import LoginPage, ThreadPage, MessagesPage, ProfilePage, PhotosPage
|
||||
from .pages import LoginPage, ThreadPage, MessagesPage, PostMessagePage, ProfilePage, PhotosPage
|
||||
|
||||
__all__ = ['OkCBrowser']
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ class OkCBrowser(BaseBrowser):
|
|||
PAGES = OrderedDict((
|
||||
('https://%s/login.*' % DOMAIN, LoginPage),
|
||||
('http://%s/messages' % DOMAIN, ThreadPage),
|
||||
('http://%s/messages\?compose=1' % DOMAIN, PostMessagePage),
|
||||
('http://%s/messages\?.*' % DOMAIN, MessagesPage),
|
||||
('http://%s/profile/.*/photos' % DOMAIN, PhotosPage),
|
||||
('http://%s/profile/[^/]*' % DOMAIN, ProfilePage),
|
||||
|
|
@ -151,22 +152,11 @@ class OkCBrowser(BaseBrowser):
|
|||
break
|
||||
return mails
|
||||
|
||||
#@check_login
|
||||
#@url2id
|
||||
#def post_mail(self, id, content):
|
||||
# new_content = u''
|
||||
# for c in content:
|
||||
# try:
|
||||
# new_content += '&%s;' % codepoint2name[ord(c)]
|
||||
# except KeyError:
|
||||
# new_content += c
|
||||
|
||||
# content = new_content.replace('\n', '\r\n').encode('Windows-1252', 'replace')
|
||||
|
||||
# try:
|
||||
# self.api_request('message', 'new', data={'memberId': id, 'message': content})
|
||||
# except AuMException, e:
|
||||
# raise CantSendMessage(unicode(e))
|
||||
@check_login
|
||||
def post_mail(self, id, content):
|
||||
self.location(self.absurl('/messages?compose=1'))
|
||||
content = content.replace('\n', '\r\n').encode('Windows-1252', 'replace')
|
||||
self.page.post_mail(id, content)
|
||||
|
||||
#@check_login
|
||||
#@url2id
|
||||
|
|
|
|||
|
|
@ -134,3 +134,10 @@ class PhotosPage(BasePage):
|
|||
def get_photos(self):
|
||||
imgs = self.parser.select(self.document.getroot(), "//div[@class='pic clearfix']//img", method='xpath')
|
||||
return [img.get('src') for img in imgs]
|
||||
|
||||
class PostMessagePage(BasePage):
|
||||
def post_mail(self, id, content):
|
||||
self.browser.select_form(name='f2')
|
||||
self.browser['r1'] = id
|
||||
self.browser['body'] = content
|
||||
self.browser.submit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue