def callback(): try: request_token = session['request_token'] verifier = request.args.get('oauth_verifier') del session['request_token'] except: print("error getting auth verifier or request_token") # todo appropriate error handling return str(sys.exc_info()) username, key, secret = utils.verify_api(request_token, verifier) user = User.query.filter_by(username=username).first() # create user if first time if user is None: user = User(username, key, secret) print("Creating user %s: %s" % (username, user,)) db.session.add(user) db.session.commit() print("Logging in user %s" % user) login_user(user) return utils.json_response({'message':'login succesful'})
def users(): """Return a list of all users.""" users = User.query.all() out = [] for user in users: out.append(user.serialize()) return utils.json_response(out)
def users(): """ an endpoint for debugging """ users = User.query.all() out = [] for user in users: out.append(user.serialize()) return utils.json_response(out)
def search(): """ twitter search endpoint search?q={Query} """ api = utils.get_user_api(current_user) query = request.args.get('q') results = api.search(q=query) output = [] for result in results: output.append(result._json) return utils.json_response(output)
def search(): """Return search results (Tweets) from Twitter for the given query. GET /search?q=:query Args: max_results -- Integer, the most tweets to return """ query = request.args.get('q') max_results_param = request.args.get('max_results', default=100, type=int) max_results_multiplier = min(max_results_param / 100, 10) max_results = max_results_multiplier * 100 return utils.json_response( [tweet._json for tweet in search_for_tweets(query, max_results)])
def search(): """Return search results (Tweets) from Twitter for the given query. GET /search?q=:query Args: max_results -- Integer, the most tweets to return """ query = request.args.get('q') max_results_param = request.args.get('max_results', default=100, type=int) max_results_multiplier = min(max_results_param/100, 10) max_results = max_results_multiplier*100 return utils.json_response([ tweet._json for tweet in search_for_tweets(query, max_results) ])
def user(): """Return the logged in user.""" return utils.json_response({ 'id': current_user.id, 'username': current_user.username })
def logout(): logout_user() return utils.json_response({'message': 'logout succesful'})
def user(): """ returns user object """ return utils.json_response({'id':current_user.id, 'username': current_user.username})