support replying on topics
This commit is contained in:
parent
c586bfb182
commit
9c54ca4b92
4 changed files with 49 additions and 10 deletions
|
|
@ -24,7 +24,7 @@ from weboob.tools.backend import BaseBackend, BackendConfig
|
|||
from weboob.tools.newsfeed import Newsfeed
|
||||
from weboob.tools.value import Value, ValueInt, ValueBackendPassword
|
||||
from weboob.tools.misc import limit
|
||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread, CantSendMessage
|
||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread
|
||||
|
||||
from .browser import PhpBB
|
||||
from .tools import rssid, url2id, id2url
|
||||
|
|
@ -33,7 +33,7 @@ from .tools import rssid, url2id, id2url
|
|||
__all__ = ['PhpBBBackend']
|
||||
|
||||
|
||||
class PhpBBBackend(BaseBackend, ICapMessages):
|
||||
class PhpBBBackend(BaseBackend, ICapMessages, ICapMessagesPost):
|
||||
NAME = 'phpbb'
|
||||
MAINTAINER = 'Romain Bignon'
|
||||
EMAIL = 'romain@weboob.org'
|
||||
|
|
@ -179,7 +179,7 @@ class PhpBBBackend(BaseBackend, ICapMessages):
|
|||
assert message.thread
|
||||
|
||||
with self.browser:
|
||||
return self.browser.post_answer(message.thread.id,
|
||||
return self.browser.post_answer(message.thread.id if message.thread else 0,
|
||||
message.title,
|
||||
message.content)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
|||
from weboob.capabilities.messages import CantSendMessage
|
||||
|
||||
from .pages.index import LoginPage
|
||||
from .pages.forum import ForumPage, TopicPage
|
||||
from .pages.forum import ForumPage, TopicPage, PostingPage
|
||||
from .tools import id2url, url2id
|
||||
|
||||
# Browser
|
||||
|
|
@ -35,6 +35,7 @@ class PhpBB(BaseBrowser):
|
|||
'https?://.*/viewforum.php\?f=(\d+)': ForumPage,
|
||||
'https?://.*/search.php\?.*': ForumPage,
|
||||
'https?://.*/viewtopic.php\?.*': TopicPage,
|
||||
'https?://.*/posting.php\?.*': PostingPage,
|
||||
'https?://.*/ucp.php\?mode=login.*': LoginPage,
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ class PhpBB(BaseBrowser):
|
|||
parent = 0
|
||||
while 1:
|
||||
for post in self.page.iter_posts():
|
||||
if post.id == stop_id:
|
||||
if post.id >= stop_id:
|
||||
return
|
||||
|
||||
post.parent = parent
|
||||
|
|
@ -116,7 +117,7 @@ class PhpBB(BaseBrowser):
|
|||
if child:
|
||||
child.parent = post.id
|
||||
yield child
|
||||
if post.id == stop_id:
|
||||
if post.id <= stop_id:
|
||||
return
|
||||
child = post
|
||||
|
||||
|
|
@ -145,4 +146,18 @@ class PhpBB(BaseBrowser):
|
|||
return post
|
||||
|
||||
def post_answer(self, topic, title, content):
|
||||
pass
|
||||
if topic == 0:
|
||||
raise CantSendMessage('Unable to create new topic for now')
|
||||
else:
|
||||
self.location('%s/%s' % (self.BASEPATH, id2url(topic)))
|
||||
assert self.is_on_page(TopicPage)
|
||||
|
||||
self.page.go_reply()
|
||||
assert self.is_on_page(PostingPage)
|
||||
|
||||
self.page.post(title, content)
|
||||
|
||||
assert self.is_on_page(PostingPage)
|
||||
error = self.page.get_error_message()
|
||||
if error:
|
||||
raise CantSendMessage('Unable to send message: %s' % error)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from .index import PhpBBPage
|
|||
from ..tools import parse_date
|
||||
|
||||
|
||||
__all__ = ['Link', 'ForumPage', 'TopicPage']
|
||||
__all__ = ['Link', 'ForumPage', 'TopicPage', 'PostingPage']
|
||||
|
||||
|
||||
class Link(object):
|
||||
|
|
@ -96,6 +96,9 @@ class TopicPage(PhpBBPage):
|
|||
text = text[:20] + u'…'
|
||||
self.forum_title = '[%s] ' % text
|
||||
|
||||
def go_reply(self):
|
||||
self.browser.follow_link(url_regex='posting\.php')
|
||||
|
||||
def next_page_url(self):
|
||||
try:
|
||||
return self.parser.select(self.document.getroot(), 'a.right-box', 1).attrib['href']
|
||||
|
|
@ -186,3 +189,22 @@ class TopicPage(PhpBBPage):
|
|||
id = int(div.attrib['id'][1:])
|
||||
return id
|
||||
|
||||
|
||||
class PostingPage(PhpBBPage):
|
||||
def post(self, title, content):
|
||||
self.browser.select_form(predicate=lambda form: form.attrs.get('id', '') == 'postform')
|
||||
self.browser.set_all_readonly(False)
|
||||
if title:
|
||||
self.browser['subject'] = title.encode('utf-8')
|
||||
self.browser['message'] = content.encode('utf-8')
|
||||
|
||||
# This code on phpbb:
|
||||
# if ($cancel || ($current_time - $lastclick < 2 && $submit))
|
||||
# {
|
||||
# /* ... */
|
||||
# redirect($redirect);
|
||||
# }
|
||||
# To prevent that shit because weboob is too fast, we simulate
|
||||
# a value of lastclick 10 seconds before.
|
||||
self.browser['lastclick'] = str(int(self.browser['lastclick']) - 10)
|
||||
self.browser.submit(name='post')
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@ class PhpBBPage(BasePage):
|
|||
links = self.document.getroot().cssselect('link[type="application/atom+xml"]')
|
||||
return links[-1].attrib['href']
|
||||
|
||||
class LoginPage(PhpBBPage):
|
||||
def get_error_message(self):
|
||||
errors = []
|
||||
for div in self.parser.select(self.document.getroot(), 'div.error'):
|
||||
for div in self.parser.select(self.document.getroot(), 'div.error,p.error'):
|
||||
if div.text:
|
||||
errors.append(div.text.strip())
|
||||
return ', '.join(errors)
|
||||
|
||||
class LoginPage(PhpBBPage):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue