def get(self):
        twitter = AppEngineTwitter()
        session = appengine_utilities.sessions.Session(writer='cookie')

        if not session.has_key('access_token'):
            twitter.set_oauth(OAUTH_KEY, OAUTH_SECRET)
            req_info = twitter.prepare_oauth_login()
            session['request_token']  = req_info['oauth_token']
            session['request_secret'] = req_info['oauth_token_secret']
            return self.redirect(req_info['url'])
            
        twitter.set_oauth(OAUTH_KEY,
                          OAUTH_SECRET,
                          session['access_token'],
                          session['access_secret'],
                          )

        twitter.friends_ids()
        friends = simplejson.loads(twitter.last_response.content)

        query = self.request.get('query')
        page  = self.request.get('page') or 1
        
        results = twitter.search(
            query.encode('utf8'),
            {'rpp': 50,
             'page': page,
             }
            )

        for result in results:
            if result['from_user_id'] in friends:
                result['is_following'] = 1
            result['unique_id'] = md5.new(result['from_user'] + result['created_at']).hexdigest()

        twitter.verify()
        my = simplejson.loads(twitter.last_response.content)

        template_values = {
            'query':   query,
            'encoded_query': urllib.quote(query.encode('utf8')),
            'results': results,
            'my':      my,
            'page':    page,
            'users':   results,
            }

        path = os.path.join(os.path.dirname(__file__), 'search.html')
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
    def get(self):
        twitter = AppEngineTwitter()
        session = appengine_utilities.sessions.Session(writer='cookie')

        if not session.has_key('access_token'):
            twitter.set_oauth(OAUTH_KEY, OAUTH_SECRET)
            req_info = twitter.prepare_oauth_login()
            session['request_token'] = req_info['oauth_token']
            session['request_secret'] = req_info['oauth_token_secret']
            return self.redirect(req_info['url'])

        twitter.set_oauth(
            OAUTH_KEY,
            OAUTH_SECRET,
            session['access_token'],
            session['access_secret'],
        )

        twitter.friends_ids()
        friends = simplejson.loads(twitter.last_response.content)

        query = self.request.get('query')
        page = self.request.get('page') or 1

        results = twitter.search(query.encode('utf8'), {
            'rpp': 50,
            'page': page,
        })

        for result in results:
            if result['from_user_id'] in friends:
                result['is_following'] = 1
            result['unique_id'] = md5.new(result['from_user'] +
                                          result['created_at']).hexdigest()

        twitter.verify()
        my = simplejson.loads(twitter.last_response.content)

        template_values = {
            'query': query,
            'encoded_query': urllib.quote(query.encode('utf8')),
            'results': results,
            'my': my,
            'page': page,
            'users': results,
        }

        path = os.path.join(os.path.dirname(__file__), 'search.html')
        self.response.out.write(template.render(path, template_values))
    def get(self):
        twitter = AppEngineTwitter()
        session = appengine_utilities.sessions.Session(writer='cookie')

        if 'access_secret' in session:
            twitter.set_oauth(OAUTH_KEY,
                              OAUTH_SECRET,
                              session['access_token'],
                              session['access_secret'],
                              )
            twitter.verify()
            template_values = {
                'my': simplejson.loads(twitter.last_response.content)
              }
            path = os.path.join(os.path.dirname(__file__), 'index.html')
            self.response.out.write(template.render(path, template_values))
        else:
            twitter.set_oauth(OAUTH_KEY, OAUTH_SECRET)
            req_info = twitter.prepare_oauth_login()
            session['request_token']  = req_info['oauth_token']
            session['request_secret'] = req_info['oauth_token_secret']
            self.redirect(req_info['url'])
Ejemplo n.º 4
0
    def get(self):
        twitter = AppEngineTwitter()
        session = appengine_utilities.sessions.Session(writer='cookie')

        if 'access_secret' in session:
            twitter.set_oauth(
                OAUTH_KEY,
                OAUTH_SECRET,
                session['access_token'],
                session['access_secret'],
            )
            twitter.verify()
            template_values = {
                'my': simplejson.loads(twitter.last_response.content)
            }
            path = os.path.join(os.path.dirname(__file__), 'index.html')
            self.response.out.write(template.render(path, template_values))
        else:
            twitter.set_oauth(OAUTH_KEY, OAUTH_SECRET)
            req_info = twitter.prepare_oauth_login()
            session['request_token'] = req_info['oauth_token']
            session['request_secret'] = req_info['oauth_token_secret']
            self.redirect(req_info['url'])