def post_message(self, message): self.sms_page.go() if self.sms_error_page.is_here(): raise CantSendMessage(self.page.get_error_message()) receivers = ";".join(list( message.receivers)) if message.receivers else self.username self.page.send_sms(message, receivers) if self.sms_error_page.is_here(): raise CantSendMessage(self.page.get_error_message()) self.confirm.open()
def post_answer(self, forum_id, topic_id, title, content): if topic_id == 0: if not forum_id: forums = self.get_forums() forums_prompt = 'Forums list:\n%s' % ('\n'.join( ['\t- %s' % f for f in forums.itervalues()])) m = re.match('\[(.*)\] (.*)', title or '') if not m: raise CantSendMessage( 'Please enter a title formatted like that:\n\t"[FORUM] SUBJECT"\n\n%s' % forums_prompt) forum_id = None for k, v in forums.iteritems(): if v.lower() == m.group(1).lower(): forum_id = k break if not forum_id: raise CantSendMessage('Forum "%s" not found.\n\n%s' % (m.group(1), forums_prompt)) self.location('%s/posting.php?mode=post&f=%d' % (self.BASEPATH, forum_id)) 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(u'Unable to send message: %s' % error) else: self.location('%s/%s' % (self.BASEPATH, id2url(topic_id))) assert self.is_on_page(TopicPage) self.page.go_reply() assert self.is_on_page(PostingPage) # Don't send title because it isn't needed in real use case # and with monboob title is something like: # Re: [Forum Name] Re: Topic Name if title is not None and title.startswith('Re:'): title = None self.page.post(title, content) assert self.is_on_page(PostingPage) error = self.page.get_error_message() if error: raise CantSendMessage(u'Unable to send message: %s' % error)
def post_mail(self, id, content): content = content.replace('\n', '\r\n') try: self.request('threads/%s' % id, data=content) except BrowserHTTPNotFound: raise CantSendMessage('Unable to send message.')
def post_message(self, message, sender): receiver = message.thread.id if self.phone_regex.match(receiver) is None: raise CantSendMessage(u'Invalid receiver: %s' % receiver) listetel = ",," + receiver #Fill the form self.browser.select_form(name="formulaire") self.browser.new_control("hidden", "autorize", {'value': ''}) self.browser.new_control("textarea", "msg", {'value': ''}) self.browser.set_all_readonly(False) self.browser["corpsms"] = message.content.encode('utf-8') self.browser["pays"] = "33" self.browser["listetel"] = listetel self.browser["reply"] = "2" self.browser["typesms"] = "2" self.browser["produit"] = "1000" self.browser["destToKeep"] = listetel self.browser["NUMTEL"] = sender self.browser["autorize"] = "1" self.browser["msg"] = message.content.encode('utf-8') self.browser.submit()
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()
def send_sms(self, message, receivers): sms_number = CleanDecimal(Regexp(CleanText('//span[@class="txt12-o"][1]/strong'), '(\d*) SMS.*'))(self.doc) if sms_number == 0: msg = CleanText('//span[@class="txt12-o"][1]')(self.doc) raise CantSendMessage(msg) form = self.get_form('//form[@name="formSMS"]') form["fieldMsisdn"] = receivers form["fieldMessage"] = message.content form.submit()
def post_message(self, message): receiver = message.thread.id username = [ subscription._login for subscription in self.get_subscription_list() if subscription.id.split("@")[0] == receiver ] if username: username = username[0] else: raise CantSendMessage(u'Cannot fetch own number.') self.optionspage.go(username=username) api_key = self.page.get_api_key() if not api_key: raise CantSendMessage( u'Cannot fetch API key for this account, is option enabled?') self.sendAPI.go(username=username, apikey=api_key, msg=message.content)
def post_message(self, message): if not self.browser.username: raise BrowserForbidden() if not message.parent: raise CantSendMessage( 'Posting news and diaries on DLFP is not supported yet') assert message.thread return self.browser.post_comment(message.thread.id, message.parent.id, message.title, message.content)
def post_comment(self, thread, reply_id, title, message): url = id2url(thread) if url is None: raise CantSendMessage('%s is not a right ID' % thread) self.location(url) assert self.is_on_page(ContentPage) self.location(self.page.get_post_comment_url()) assert self.is_on_page(NewCommentPage) self.select_form(predicate=self._is_comment_submit_form) self.set_all_readonly(False) if title is not None: self['comment[title]'] = title.encode('utf-8') self['comment[wiki_body]'] = message.encode('utf-8') if int(reply_id) > 0: self['comment[parent_id]'] = str(reply_id) self['commit'] = 'Poster le commentaire' try: self.submit() except BrowserHTTPError, e: raise CantSendMessage('Unable to send message to %s.%s: %s' % (thread, reply_id, e))
def post_message(self, message): assert message.thread forum = 0 topic = 0 if message.thread: try: if '.' in message.thread.id: forum, topic = [int(i) for i in message.thread.id.split('.', 1)] else: forum = int(message.thread.id) except ValueError: raise CantSendMessage('Thread ID must be in form "FORUM_ID[.TOPIC_ID]".') return self.browser.post_answer(forum, topic, message.title, message.content)
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)
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, self.config['phonenumber'].get())
class DLFP(BaseBrowser): DOMAIN = 'linuxfr.org' PROTOCOL = 'https' PAGES = {'https?://[^/]*linuxfr\.org/?': IndexPage, 'https?://[^/]*linuxfr\.org/compte/connexion': LoginPage, 'https?://[^/]*linuxfr\.org/news/[^\.]+': ContentPage, 'https?://[^/]*linuxfr\.org/wiki/(?!nouveau)[^/]+': ContentPage, 'https?://[^/]*linuxfr\.org/wiki': WikiEditPage, 'https?://[^/]*linuxfr\.org/wiki/nouveau': WikiEditPage, 'https?://[^/]*linuxfr\.org/wiki/[^\.]+/modifier': WikiEditPage, 'https?://[^/]*linuxfr\.org/suivi/[^\.]+': ContentPage, 'https?://[^/]*linuxfr\.org/sondages/[^\.]+': ContentPage, 'https?://[^/]*linuxfr\.org/users/[^\./]+/journaux/[^\.]+': ContentPage, 'https?://[^/]*linuxfr\.org/forums/[^\./]+/posts/[^\.]+': ContentPage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments/(\d+)': CommentPage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments/nouveau': NewCommentPage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments': NodePage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/tags/nouveau': NewTagPage, 'https?://[^/]*linuxfr\.org/board/index.xml': BoardIndexPage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments.atom': RSSComment, } last_board_msg_id = None def parse_id(self, _id): if re.match('^https?://.*linuxfr.org/nodes/\d+/comments/\d+$', _id): return _id, None url = id2url(_id) if url is None: if url2id(_id) is not None: url = _id _id = url2id(url) else: return None, None return url, _id def get_wiki_content(self, _id): url, _id = self.parse_id('W.%s' % _id) if url is None: return None try: self.location('%s/modifier' % url) except BrowserHTTPNotFound: return '' assert self.is_on_page(WikiEditPage) return self.page.get_body() def _go_on_wiki_edit_page(self, name): """ Go on the wiki page named 'name'. Return True if this is a new page, or False if the page already exist. Return None if it isn't a right wiki page name. """ url, _id = self.parse_id('W.%s' % name) if url is None: return None try: self.location('%s/modifier' % url) except BrowserHTTPNotFound: self.location('/wiki/nouveau') new = True else: new = False assert self.is_on_page(WikiEditPage) return new def set_wiki_content(self, name, content, message): new = self._go_on_wiki_edit_page(name) if new is None: return None if new: title = name.replace('-', ' ') else: title = None self.page.post_content(title, content, message) def get_wiki_preview(self, name, content): if self._go_on_wiki_edit_page(name) is None: return None self.page.post_preview(content) if self.is_on_page(WikiEditPage): return self.page.get_preview_html() elif self.is_on_page(ContentPage): return self.page.get_article().body def get_hash(self, url): self.location(url) myhash = hashlib.md5(lxml.etree.tostring(self.page.document)).hexdigest() return myhash def get_content(self, _id): url, _id = self.parse_id(_id) if url is None: return None self.location(url) self.page.url = self.absurl(url) if self.is_on_page(CommentPage): content = self.page.get_comment() elif self.is_on_page(ContentPage): m = re.match('.*#comment-(\d+)$', url) if m: content = self.page.get_comment(int(m.group(1))) else: content = self.page.get_article() else: raise BrokenPageError('Not on a content or comment page (%r)' % self.page) if _id is not None: content.id = _id return content def _is_comment_submit_form(self, form): return 'comment_new' in form.action def post_comment(self, thread, reply_id, title, message): url = id2url(thread) if url is None: raise CantSendMessage('%s is not a right ID' % thread) self.location(url) assert self.is_on_page(ContentPage) self.location(self.page.get_post_comment_url()) assert self.is_on_page(NewCommentPage) self.select_form(predicate=self._is_comment_submit_form) self.set_all_readonly(False) if title is not None: self['comment[title]'] = title.encode('utf-8') self['comment[wiki_body]'] = message.encode('utf-8') if int(reply_id) > 0: self['comment[parent_id]'] = str(reply_id) self['commit'] = 'Poster le commentaire' try: self.submit() except BrowserHTTPError, e: raise CantSendMessage('Unable to send message to %s.%s: %s' % (thread, reply_id, e)) if self.is_on_page(NodePage): errors = self.page.get_errors() if len(errors) > 0: raise CantSendMessage('Unable to send message: %s' % ', '.join(errors)) return None