-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
40 lines (33 loc) · 1.22 KB
/
application.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import urls
import models
import tornadoredis
import tornado.ioloop
import tornado.web
import tornado.auth
import tornado.options
from peewee import SqliteDatabase
class Application(tornado.web.Application):
db = SqliteDatabase('chat.db')
client = tornadoredis.Client()
def __init__(self):
settings = dict(
cookie_secret="2.l,!G7391(+Zj9iadZ^hU%ou0kMO@AKq5573QOmVLW}UvLbwP8tm79Y35Y",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
autoreload=True,
debug=True,
gzip=True
)
tornado.web.Application.__init__(self, urls.urls_handlers, **settings)
self.client.connect()
self.client.flushall() # flush all redis keys after restart server
self.db.create_tables([models.User], True)
def start_chat_server():
tornado.options.define("port", default=8000, help="Run server on the given port", type=int)
tornado.options.parse_command_line()
application = Application()
application.listen(tornado.options.options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
start_chat_server()