Created
November 9, 2010 18:23
-
-
Save brimcfadden/669536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import tornado.httpclient | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): | |
print "taking request" | |
http = tornado.httpclient.AsyncHTTPClient() | |
http.fetch("http://friendfeed-api.com/v2/feed/bret", | |
callback=self.on_response) | |
def on_response(self, response): | |
print "on_response" | |
if response.error: raise tornado.web.HTTPError(500) | |
json = tornado.escape.json_decode(response.body) | |
self.write("Fetched " + str(len(json["entries"])) + " entries " | |
"from the FriendFeed API") | |
self.finish() | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
http_server = tornado.httpserver.HTTPServer(application) | |
http_server.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment