예제 #1
0
    def test_tw_api(self):
        # auth
        token = tw_api.get_authtoken()
        self.assertTrue(token)
        print token

        # top-tweets
        res = tw_api.get_toptweets(token, "New Spiderman")
        self.assertEqual(type(res), tuple)
        self.assertEqual(res[0], 200)
        self.assertTrue(isinstance(res[1], list))
예제 #2
0
def toptweets():
    """  
    request: /GET  /api/tweets/top?q=Query 

    response:  200, { tweets:[tweet] }   |  400, {reason:"error message"}
    """
    q = request.args.get('q', '')
    if not q:
        return err("Empty query is not valid")
     
    token = get_token()
    status, res = tw_api.get_toptweets(token, q)
    if status != 200:
        return err(res)

    return jsonify(dict(tweets=res))