mirror of
https://github.com/e1ven/Robohash.git
synced 2025-06-23 21:35:02 +00:00
specify port
This commit is contained in:
parent
eeb5494e13
commit
4940d9c43a
30
webfront.py
30
webfront.py
@ -16,11 +16,13 @@ import Image
|
|||||||
import hashlib
|
import hashlib
|
||||||
import urllib
|
import urllib
|
||||||
import random
|
import random
|
||||||
|
from tornado.options import define, options
|
||||||
try:
|
try:
|
||||||
from hashlib import md5 as md5_func
|
from hashlib import md5 as md5_func
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from md5 import new as md5_func
|
from md5 import new as md5_func
|
||||||
|
|
||||||
|
define("port", default=80, help="run on the given port", type=int)
|
||||||
|
|
||||||
class Robohash(object):
|
class Robohash(object):
|
||||||
def __init__(self,string):
|
def __init__(self,string):
|
||||||
@ -135,15 +137,33 @@ class ImgHandler(tornado.web.RequestHandler):
|
|||||||
robohash = Image.merge("RGB", (r, g, b))
|
robohash = Image.merge("RGB", (r, g, b))
|
||||||
robohash.save(self,format=ext)
|
robohash.save(self,format=ext)
|
||||||
|
|
||||||
application = tornado.web.Application([
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
tornado.options.parse_command_line()
|
||||||
|
# timeout in seconds
|
||||||
|
timeout = 10
|
||||||
|
socket.setdefaulttimeout(timeout)
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"static_path": os.path.join(os.path.dirname(__file__), "static"),
|
||||||
|
"cookie_secret": "9b90a85cfe46cad5ec136ee44a3fa332",
|
||||||
|
"login_url": "/login",
|
||||||
|
"xsrf_cookies": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
application = tornado.web.Application([
|
||||||
(r"/static/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__),
|
(r"/static/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(os.path.dirname(__file__),
|
||||||
"static/")}),
|
"static/")}),
|
||||||
|
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/(.*)", ImgHandler),
|
(r"/(.*)", ImgHandler),
|
||||||
|
], **settings)
|
||||||
|
|
||||||
])
|
http_server = tornado.httpserver.HTTPServer(application)
|
||||||
|
http_server.listen(options.port)
|
||||||
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
application.listen(8080)
|
main()
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user