Exemplo n.º 1
0
    def test_is_username(self):
        valid = ['dialelo', 'mental_floss', '4n_4Wfu1_US3RN4M3']
        for user in valid:
            self.failUnless(is_username(user))

        invalid = ['-asd', 'adsd?']

        for user in invalid:
            self.failIf(is_username(user))
Exemplo n.º 2
0
    def test_is_username(self):
        valid = ['dialelo', 'mental_floss', '4n_4Wfu1_US3RN4M3']
        for user in valid:
            self.failUnless(is_username(user))

        invalid = ['-asd', 'adsd?']

        for user in invalid:
            self.failIf(is_username(user))
Exemplo n.º 3
0
    def search_user_handler(self, username):
        """
        Handles creating a timeline tracking the searched user's tweets.
        """
        if username is None:
            self.info_message(_('Search cancelled'))
            return

        # TODO make sure that the user EXISTS and THEN fetch its tweets
        username = sanitize_username(username)
        if not is_username(username):
            self.info_message(_('Invalid username'))
            return
        else:
            self.info_message(_('Fetching latest tweets from @%s' % username))

        success_message = _('@%s\'s timeline created' % username)
        timeline_created = partial(self.info_message,
                                   success_message)
        error_message = _('Unable to create @%s\'s timeline' % username)
        timeline_not_created = partial(self.error_message,
                                       error_message)

        self.append_timeline(name='@%s' % username,
                             update_function=self.api.get_user_timeline,
                             update_args=username,
                             on_success=timeline_created,
                             on_error=timeline_not_created)
Exemplo n.º 4
0
    def unfollow_user_handler(self, username):
        """
        Handles unfollowing the user given in `username`.
        """
        if username is None:
            self.info_message(_('Search cancelled'))
            return

        username = sanitize_username(username)
        if username == self.user.screen_name:
            self.error_message(_('That doesn\'t make any sense'))
            return

        # TODO make sure that the user EXISTS and THEN follow
        if not is_username(username):
            self.info_message(_('Invalid username'))
            return
        else:
            self.info_message(_('Unfollowing @%s' % username))

        success_message = _('You are no longer following %s' % username)
        unfollow_done = partial(self.info_message,
                                success_message)

        error_template = _('We can not ensure that you are not following %s')
        error_message = error_template % username
        unfollow_error = partial(self.error_message,
                                 error_message)

        self.api.destroy_friendship(screen_name=username,
                                    on_error=unfollow_error,
                                    on_success=unfollow_done)
Exemplo n.º 5
0
    def follow_user_handler(self, username):
        """
        Handles following the user given in `username`.
        """
        if username is None:
            self.info_message(_('Search cancelled'))
            return

        username = sanitize_username(username)
        if username == self.user.screen_name:
            self.error_message(_('You can\'t follow yourself'))
            return

        # TODO make sure that the user EXISTS and THEN follow
        if not is_username(username):
            self.info_message(_('Invalid username'))
            return
        else:
            self.info_message(_('Following @%s' % username))

        success_message = _('You are now following @%s' % username)
        follow_done = partial(self.info_message,
                              success_message)

        error_template = _('We can not ensure that you are following @%s')
        error_message = error_template % username
        follow_error = partial(self.error_message,
                               error_message)

        self.api.create_friendship(screen_name=username,
                                   on_error=follow_error,
                                   on_success=follow_done)
Exemplo n.º 6
0
    def search_user_handler(self, username):
        """
        Handles creating a timeline tracking the searched user's tweets.
        """
        self.ui.remove_editor(self.search_user_handler)
        self.ui.set_focus('body')

        # TODO make sure that the user EXISTS and THEN fetch its tweets
        username = sanitize_username(username)
        if not is_username(username):
            self.info_message(_('Invalid username'))
            return
        else:
            self.info_message(_('Fetching latest tweets from @%s' % username))

        timeline_created = partial(self.info_message,
                                  _('@%s\'s timeline created' % username))
        timeline_not_created = partial(self.error_message,
                                       _('Unable to create @%s\'s timeline' % username))

        self.append_timeline(name='@%s' % username,
                             update_function=self.api.get_user_timeline, 
                             update_args=username,
                             on_success=timeline_created,
                             on_error=timeline_not_created)
Exemplo n.º 7
0
Arquivo: ui.py Projeto: gigigi/turses
 def apply_attribute(string):
     if is_hashtag(string):
         return ('hashtag', string)
     elif string.startswith('@') and is_username(string[1:-1]):
         # we can lose some characters here..
         username = sanitize_username(string)
         return ('attag', '@' + username)
     else:
         return  string