Exemple #1
0
    def test_is_DM(self):
        # status is NOT a DM
        status = create_status()
        self.failIf(is_DM(status))

        dm = create_direct_message()
        self.failUnless(is_DM(dm))
Exemple #2
0
    def test_is_DM(self):
        # status is NOT a DM
        status = create_status()
        self.assertFalse(is_DM(status))

        dm = create_direct_message()
        self.assertTrue(is_DM(dm))
Exemple #3
0
    def test_is_DM(self):
        # status is NOT a DM
        status = create_status()
        self.failIf(is_DM(status))

        dm = create_direct_message()
        self.failUnless(is_DM(dm))
Exemple #4
0
    def append_thread_timeline(self):
        status = self.timelines.active_status

        timeline_fetched = partial(self.info_message,
                                   _('Thread fetched'))
        timeline_not_fetched = partial(self.error_message,
                                       _('Failed to fetch thread'))

        if is_DM(status):
            participants = [status.sender_screen_name,
                            status.recipient_screen_name]
            name = _('DM thread: %s' % ', '.join(participants))
            update_function = self.api.get_message_thread
        else:
            participants = status.mentioned_usernames
            author = status.authors_username
            if author not in participants:
                participants.insert(0, author)

            name = _('thread: %s' % ', '.join(participants))
            update_function = self.api.get_thread

        self.append_timeline(name=name,
                             update_function=update_function,
                             update_args=status,
                             on_error=timeline_not_fetched,
                             on_success=timeline_fetched)
Exemple #5
0
    def thread(self, status):
        """
        Create a timeline with the conversation to which `status` belongs.
        `status` can be a regular status or a direct message.
        """
        if is_DM(status):
            participants = [
                status.sender_screen_name, status.recipient_screen_name
            ]
            name = _('DM thread: %s' % ', '.join(participants))
            update_function = self.api.get_message_thread
        else:
            participants = status.mentioned_usernames
            author = status.authors_username
            if author not in participants:
                participants.insert(0, author)

            name = _('thread: %s' % ', '.join(participants))
            update_function = self.api.get_thread

        return Timeline(
            name=name,
            update_function=update_function,
            update_function_args=status,
        )
Exemple #6
0
    def append_thread_timeline(self):
        status = self.timelines.active_status

        timeline_fetched = partial(self.info_message, _('Thread fetched'))
        timeline_not_fetched = partial(self.error_message,
                                       _('Failed to fetch thread'))

        if is_DM(status):
            participants = [
                status.sender_screen_name, status.recipient_screen_name
            ]
            name = _('DM thread: %s' % ', '.join(participants))
            update_function = self.api.get_message_thread
        else:
            participants = status.mentioned_usernames
            author = status.authors_username
            if author not in participants:
                participants.insert(0, author)

            name = _('thread: %s' % ', '.join(participants))
            update_function = self.api.get_thread

        self.append_timeline(name=name,
                             update_function=update_function,
                             update_args=status,
                             on_error=timeline_not_fetched,
                             on_success=timeline_fetched)
Exemple #7
0
    def retweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.error_message(_('You can\'t retweet direct messages'))
            return

        self._retweet(status)
Exemple #8
0
    def retweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.error_message(_('You can\'t retweet direct messages'))
            return

        self._retweet(status)
Exemple #9
0
    def __init__(self, status):
        self.status = status

        header_text = self._create_header(status)
        text = map_attributes(status, hashtag="hashtag", attag="attag", url="url")

        is_favorite = not is_DM(status) and status.is_favorite
        widget = self._build_widget(header_text, text, is_favorite)

        self.__super.__init__(widget)
Exemple #10
0
    def open_status_url(self):
        """
        Open the focused tweet in a browser.
        """
        status = self.timelines.active_status

        if is_DM(status):
            message = _('You only can open regular statuses in a browser')
            self.info_message(message)
            return

        self.open_urls_in_browser([status.url])
Exemple #11
0
    def open_status_url(self):
        """
        Open the focused tweet in a browser.
        """
        status = self.timelines.active_status

        if is_DM(status):
            message = _('You only can open regular statuses in a browser')
            self.info_message(message)
            return

        self.open_urls_in_browser([status.url])
Exemple #12
0
    def __init__(self, status, configuration):
        self.status = status
        self.configuration = configuration

        header_text = self._create_header(status)
        text = status.map_attributes(hashtag='hashtag',
                                     attag='attag',
                                     url='url')

        is_favorite = not is_DM(status) and status.is_favorite
        widget = self._build_widget(header_text, text, is_favorite)

        self.__super.__init__(widget)
Exemple #13
0
    def __init__(self, status):
        self.status = status

        header_text = self._create_header(status)
        text = map_attributes(status,
                              hashtag='hashtag',
                              attag='attag',
                              url='url')

        is_favorite = not is_DM(status) and status.is_favorite
        widget = self._build_widget(header_text, text, is_favorite)

        self.__super.__init__(widget)
Exemple #14
0
    def retweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.error_message(_('You can\'t retweet direct messages'))
            return

        retweet_posted = partial(self.info_message,
                                 _('Retweet posted'))
        retweet_post_failed = partial(self.error_message,
                                      _('Failed to post retweet'))
        self.api.retweet(on_error=retweet_post_failed,
                         on_success=retweet_posted,
                         status=status,)
Exemple #15
0
    def __init__ (self, status, configuration):
        self.status = status
        self.configuration = configuration

        text = self.apply_attributes(status.text)
        status_content = Padding(AttrMap(Text(text), 'body'), left=1, right=1)
        header = self._create_header(status)
        box = BoxDecoration(status_content, title=header)

        if not is_DM(status) and status.is_favorite:
            widget = AttrMap(box, 'favorited', 'focus')
        else:
            widget = AttrMap(box, 'line', 'focus')
        self.__super.__init__(widget)
Exemple #16
0
    def retweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.error_message(_('You can\'t retweet direct messages'))
            return

        retweet_posted = partial(self.info_message, _('Retweet posted'))
        retweet_post_failed = partial(self.error_message,
                                      _('Failed to post retweet'))
        self.api.retweet(
            on_error=retweet_post_failed,
            on_success=retweet_posted,
            status=status,
        )
Exemple #17
0
    def open_status_url(self):
        """
        Display URL for the focused tweet.
        """
        status = self.timelines.active_status

        if is_DM(status):
            message = _('You only can open regular statuses in a browser')
            self.info_message(message)
            return

        if configuration.styles['no_webbrowser']:
            self.ui.show_status_info(status)
            self.status_info_mode()
        else:
            self.open_urls_in_browser([status.url]) 
Exemple #18
0
    def reply(self):
        status = self.timelines.get_active_status()
        if status is None:
            return
        if is_DM(status):
            self.direct_message()
            return

        author = get_authors_username(status)
        mentioned = get_mentioned_for_reply(status)
        try:
            mentioned.remove('@%s' % self.user.screen_name)
        except ValueError:
            pass

        self.ui.show_tweet_editor(prompt=_('Reply to %s' % author),
                                  content=' '.join(mentioned),
                                  done_signal_handler=self.tweet_handler)
Exemple #19
0
    def reply(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.direct_message()
            return

        author = status.authors_username
        mentioned = status.mentioned_for_reply
        try:
            mentioned.remove('@%s' % self.user.screen_name)
        except ValueError:
            pass

        handler = self.reply_handler
        editor = self.ui.show_tweet_editor(prompt=_('Reply to %s' % author),
                                           content=' '.join(mentioned),
                                           done_signal_handler=handler)
        self.editor_mode(editor)
Exemple #20
0
    def delete_tweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.delete_dm()
            return

        author = status.authors_username
        if author != self.user.screen_name and status.user != self.user.screen_name:
            self.error_message(_('You can only delete your own tweets'))
            return

        status_deleted = partial(self.info_message, _('Tweet deleted'))
        status_not_deleted = partial(self.error_message,
                                     _('Failed to delete tweet'))

        self.api.destroy_status(status=status,
                                on_error=status_not_deleted,
                                on_success=status_deleted)
Exemple #21
0
    def reply(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.direct_message()
            return

        author = status.authors_username
        mentioned = status.mentioned_for_reply
        try:
            mentioned.remove('@%s' % self.user.screen_name)
        except ValueError:
            pass

        handler = self.reply_handler
        editor = self.ui.show_tweet_editor(prompt=_('Reply to %s' % author),
                                           content=' '.join(mentioned),
                                           done_signal_handler=handler)
        self.editor_mode(editor)
Exemple #22
0
    def _create_header(self, status):
        """
        Return the header text for the status associated with this widget.
        """
        if is_DM(status):
            return self._dm_header(status)

        reply = ''
        retweeted = ''
        retweet_count = ''
        retweeter = ''
        username = status.user
        relative_created_at = status.relative_created_at

        # reply
        if status.is_reply:
            reply = surround_with_spaces(
                configuration.styles['reply_indicator'])

        # retweet
        if status.is_retweet:
            retweeted = surround_with_spaces(
                configuration.styles['retweet_indicator'])
            # `username` is the author of the original tweet
            username = status.author
            # `retweeter` is the user who made the RT
            retweeter = status.user
            retweet_count = str(status.retweet_count)

        # create header
        styles = configuration.styles
        header_template = ' ' + styles.get('header_template') + ' '
        header = str(header_template).format(
            username=username,
            retweeted=retweeted,
            retweeter=retweeter,
            time=relative_created_at,
            reply=reply,
            retweet_count=retweet_count,
        )

        return encode(header)
Exemple #23
0
    def _create_header(self, status):
        """
        Return the header text for the status associated with this widget.
        """
        if is_DM(status):
            return self._dm_header(status)

        reply = ''
        retweeted = ''
        retweet_count = ''
        retweeter = ''
        username = status.user
        relative_created_at = status.relative_created_at

        # reply
        if status.is_reply:
            reply = surround_with_spaces(
                configuration.styles['reply_indicator'])

        # retweet
        if status.is_retweet:
            retweeted = surround_with_spaces(
                configuration.styles['retweet_indicator'])
            # `username` is the author of the original tweet
            username = status.author
            # `retweeter` is the user who made the RT
            retweeter = status.user
            retweet_count = str(status.retweet_count)

        # create header
        styles = configuration.styles
        header_template = ' ' + styles.get('header_template') + ' '
        header = str(header_template).format(
            username=username,
            retweeted=retweeted,
            retweeter=retweeter,
            time=relative_created_at,
            reply=reply,
            retweet_count=retweet_count,
        )

        return encode(header)
Exemple #24
0
    def delete_tweet(self):
        status = self.timelines.active_status

        if is_DM(status):
            self.delete_dm()
            return

        author = status.authors_username
        if author != self.user.screen_name and status.user != self.user.screen_name:
            self.error_message(_('You can only delete your own tweets'))
            return

        status_deleted = partial(self.info_message,
                                 _('Tweet deleted'))
        status_not_deleted = partial(self.error_message,
                                     _('Failed to delete tweet'))

        self.api.destroy_status(status=status,
                                on_error=status_not_deleted,
                                on_success=status_deleted)
Exemple #25
0
    def _create_header(self, status):
        """
        Return the header text for the status associated with this widget.
        """
        if is_DM(status):
            return self._dm_header(status)

        reply = ""
        retweeted = ""
        retweet_count = ""
        retweeter = ""
        username = status.user
        relative_created_at = status.relative_created_at

        # reply
        if status.is_reply:
            reply = u" \u2709"

        # retweet
        if status.is_retweet:
            retweeted = u" \u267b "
            # `username` is the author of the original tweet
            username = status.author
            # `retweeter` is the user who made the RT
            retweeter = status.user
            retweet_count = str(status.retweet_count)

        # create header
        styles = self.configuration.styles
        header_template = " " + styles.get("header_template") + " "
        header = unicode(header_template).format(
            username=username,
            retweeted=retweeted,
            retweeter=retweeter,
            time=relative_created_at,
            reply=reply,
            retweet_count=retweet_count,
        )

        return encode(header)
Exemple #26
0
    def thread(self, status):
        """
        Create a timeline with the conversation to which `status` belongs.
        `status` can be a regular status or a direct message.
        """
        if is_DM(status):
            participants = [status.sender_screen_name,
                            status.recipient_screen_name]
            name = _('DM thread: %s' % ', '.join(participants))
            update_function = self.api.get_message_thread
        else:
            participants = status.mentioned_usernames
            author = status.authors_username
            if author not in participants:
                participants.insert(0, author)

            name = _('thread: %s' % ', '.join(participants))
            update_function = self.api.get_thread

        return Timeline(name=name,
                        update_function=update_function,
                        update_function_args=status,)
Exemple #27
0
    def append_thread_timeline(self):
        status = self.timelines.active_status

        timeline_fetched = partial(self.info_message, _('Thread fetched'))
        timeline_not_fetched = partial(self.error_message,
                                       _('Failed to fetch thread'))

        if is_DM(status):
            self.error_message(_('Doesn\'t look like a public conversation'))
            return

        participants = status.mentioned_usernames
        author = status.authors_username
        if author not in participants:
            participants.insert(0, author)

        name = _('thread: %s' % ', '.join(participants))
        self.append_timeline(name=name,
                             update_function=self.api.get_thread,
                             update_args=status,
                             on_error=timeline_not_fetched,
                             on_success=timeline_fetched)
Exemple #28
0
Fichier : ui.py Projet : apg/turses
    def _create_header(self, status):
        """Return the header text for the status associated with this widget."""
        if is_DM(status):
            return self._dm_header(status)

        # tweet or retweet
        reply = ''
        retweeted = ''
        retweet_count = ''
        retweeter = ''
        username = status.user
        relative_created_at = status.get_relative_created_at()

        # reply
        if status.is_reply:
            reply = u' \u2709'

        # retweet
        if status.is_retweet:
            retweeted = u" \u267b "
            # `username` is the author of the original tweet
            username = status.author
            # `retweeter` is the user who made the RT
            retweeter = status.user
            retweet_count = str(status.retweet_count)

        # create header
        header_template = ' ' + self.configuration.styles['header_template'] + ' '
        header = unicode(header_template).format(
            username=username,
            retweeted=retweeted,
            retweeter=retweeter,
            time=relative_created_at,
            reply=reply,
            retweet_count=retweet_count,
        )

        return encode(header)
Exemple #29
0
    def delete_tweet(self):
        status = self.timelines.get_active_status()
        if status is None:
            return
        if is_DM(status): 
            self.delete_dm()
            return

        author = get_authors_username(status)
        if author != self.user.screen_name:
            self.error_message(_('You can only delete your own tweets'))
            return

        # TODO: check if DM and delete DM if is

        status_deleted = partial(self.info_message, 
                                 _('Tweet deleted'))
        status_not_deleted = partial(self.error_message, 
                                     _('Failed to delete tweet'))

        self.api.destroy_status(status=status, 
                                on_error=status_not_deleted,
                                on_success=status_deleted)
Exemple #30
0
    def append_thread_timeline(self):
        status = self.timelines.active_status

        timeline_fetched = partial(self.info_message,
                                   _('Thread fetched'))
        timeline_not_fetched = partial(self.error_message,
                                       _('Failed to fetch thread'))

        if is_DM(status):
            self.error_message(_('Doesn\'t look like a public conversation'))
            return

        participants = status.mentioned_usernames
        author = status.authors_username
        if author not in participants:
            participants.insert(0, author)

        name = _('thread: %s' % ', '.join(participants))
        self.append_timeline(name=name,
                             update_function=self.api.get_thread,
                             update_args=status,
                             on_error=timeline_not_fetched,
                             on_success=timeline_fetched)
Exemple #31
0
 def create_favorite(self, status):
     if is_DM(status) or status.is_favorite:
         raise Exception
     args = status,
     favorite_thread = Thread(target=self._api.create_favorite, args=args)
     favorite_thread.start()
Exemple #32
0
 def create_favorite(self, status):
     if is_DM(status) or status.is_favorite:
         raise Exception
     self._api.create_favorite(status)
Exemple #33
0
 def create_favorite(self, status):
     if is_DM(status) or status.is_favorite:
         raise Exception
     self._api.create_favorite(status)