Feb
19
Tornado Async Twitter Feed
Tornado's AsyncHTTPClient is a very simple way to make RESTful API calls. Adding the Twitter feed to my blog was just a couple of lines of code:
class HomeHandler(BaseHandler):
@tornado.web.asynchronous
def get(self):
http = tornado.httpclient.AsyncHTTPClient()
http.fetch("http://api.twitter.com/1/statuses/user_timeline.json?" \
"screen_name=username&include_rts=t",
callback=self.on_response)
def on_response(self, response):
latest_entries = self.redis.lrange('latest', 0, 15)
tweets = tornado.escape.json_decode(response.body)
...
Could it be any easier??