-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (22 loc) · 781 Bytes
/
main.py
File metadata and controls
26 lines (22 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado import gen
from tornado.httpclient import AsyncHTTPClient
class MainHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
http_client = AsyncHTTPClient()
response = yield http_client.fetch("http://www.sinacloud.com")
self.set_header('content-type', 'text/plain')
self.write('Hello, World! ' + str(response.body[:100]))
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(5050 or os.environ['PORT'])
tornado.ioloop.IOLoop.current().start()