Beispiel #1
0
    def test_get_mentioned_usernames(self):
        user = '******'
        mentioned = ('dialelo', 'mental_floss', '4n_4Wfu1_US3RN4M3')

        expected_output = list(mentioned)

        text = "@%s, @%s and @%s" % mentioned
        status = create_status(user=user, text=text)

        expected = set(expected_output)
        mentioned_usernames = get_mentioned_usernames(status)
        self.assertEqual(expected, set(mentioned_usernames))
Beispiel #2
0
    def test_get_mentioned_usernames(self):
        user = '******'
        mentioned = ('dialelo', 'mental_floss', '4n_4Wfu1_US3RN4M3')

        expected_output = list(mentioned)

        text = "@%s, @%s and @%s" % mentioned
        status = create_status(user=user,
                               text=text)

        expected = set(expected_output)
        mentioned_usernames = get_mentioned_usernames(status)
        self.assertEqual(expected, set(mentioned_usernames))
Beispiel #3
0
    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)
Beispiel #4
0
    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)