예제 #1
0
    def test_get_authors_username(self):
        user = '******'

        # tweet
        status = create_status(user=user)
        author = get_authors_username(status)
        self.assertEqual(user, author)

        # retweet
        retweeter = 'bot'
        retweet = create_status(user=retweeter, is_retweet=True, author=user)
        author = get_authors_username(retweet)
        self.assertEqual(user, author)

        # direct message
        dm = create_direct_message(sender_screen_name=user, )
        author = get_authors_username(dm)
        self.assertEqual(user, author)
예제 #2
0
    def test_get_authors_username(self):
        user = '******'

        # tweet
        status = create_status(user=user)
        author = get_authors_username(status)
        self.assertEqual(user, author)

        # retweet
        retweeter = 'bot'
        retweet = create_status(user=retweeter,
                                is_retweet=True,
                                author=user)
        author = get_authors_username(retweet)
        self.assertEqual(user, author)

        # direct message
        dm = create_direct_message(sender_screen_name=user,)
        author = get_authors_username(dm)
        self.assertEqual(user, author)
예제 #3
0
파일: core.py 프로젝트: gigigi/turses
 def unfollow_selected(self):
     status = self.timelines.get_active_status()
     if status is None:
         return
     username = get_authors_username(status)
     if username == self.user.screen_name:
         self.error_message(_('That doesn\'t make any sense'))
         return
     unfollow_done = partial(self.info_message, 
                             _('You are no longer following %s' % username))
     unfollow_error = partial(self.error_message, 
                            _('We can not ensure that you are not following %s' % username))
     self.api.destroy_friendship(screen_name=username, 
                                 on_error=unfollow_error,
                                 on_success=unfollow_done)
예제 #4
0
파일: core.py 프로젝트: gigigi/turses
 def follow_selected(self):
     status = self.timelines.get_active_status()
     if status is None:
         return
     username = get_authors_username(status)
     if username == self.user.screen_name:
         self.error_message(_('You can\'t follow yourself'))
         return
     follow_done = partial(self.info_message, 
                           _('You are now following @%s' % username))
     follow_error = partial(self.error_message, 
                            _('We can not ensure that you are following @%s' % username))
     self.api.create_friendship(screen_name=username, 
                                on_error=follow_error,
                                on_success=follow_done)
예제 #5
0
파일: backends.py 프로젝트: apg/turses
    def get_thread(self, status, **kwargs):
        author = get_authors_username(status)
        mentioned = get_mentioned_usernames(status)
        if author not in mentioned:
            mentioned.append(author)

        tweets = []
        for username in mentioned:
            tweets.extend(self.get_user_timeline(username, **kwargs))

        def belongs_to_conversation(status):
            for username in mentioned:
                if username in status.text:
                    return True

        return filter(belongs_to_conversation, tweets)
예제 #6
0
파일: core.py 프로젝트: gigigi/turses
    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)
예제 #7
0
파일: core.py 프로젝트: gigigi/turses
    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)
예제 #8
0
파일: core.py 프로젝트: gigigi/turses
    def append_thread_timeline(self):
        status = self.timelines.get_active_status()
        if status is None:
            return

        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'))
        else:
            participants = get_mentioned_usernames(status)
            author = get_authors_username(status)
            if author not in participants:
                participants.insert(0, author)

            self.append_timeline(name=_('thread: %s' % ', '.join(participants)),
                                 update_function=self.api.get_thread, 
                                 update_args=status,
                                 on_error=timeline_not_fetched,
                                 on_success=timeline_fetched)
예제 #9
0
파일: ui.py 프로젝트: gigigi/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 "
            retweeter = username
            author = get_authors_username(status)
            username = author 
            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)
예제 #10
0
파일: core.py 프로젝트: gigigi/turses
 def focused_status_author_timeline(self):
     status = self.timelines.get_active_status()
     if status is None:
         return
     author = get_authors_username(status)
     self.append_user_timeline(author)