Demo entry 6659127

application

   

Submitted by anonymous on Nov 09, 2017 at 10:05
Language: Python 3. Code size: 2.3 kB.

#-*- coding:utf8 -*-

__author__ = 'caoxinyu'
__email__ = "caoxinyu@niot.cn"
__filename__ = "app.py"
__copyright__ = "Copyright 2015,NIOT"
__version__ = "1.0.0"
__deprecated__ = False
__date__ = "2015-04-22"

import os.path

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
from sqlalchemy.orm import scoped_session, sessionmaker
from motor import MotorClient

from base import BaseHandler
from src.model.db import engine
from src.model.mongo_config import mongo_uri, mongo_db_name
from src.view import *
from src.modules.auth import auth_timer

define("port", default=81, type=int, help="run on the given port")


class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/", Hello),
            (r"/sid", SIDHandler),
            (r"/agent", AgentHandler)
        ]
        settings = dict(
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            template_path=os.path.join(os.path.dirname(__file__), 'templates'),
            static_path=os.path.join(os.path.dirname(__file__), 'static'),
            # xsrf cookies=True,
            autoescape=None,
            # mongo_db=MotorClient(mongo_uri)[mongo_db_name],
            debug=False,
        )
        print("-------------------------------Application start!!!")
        tornado.web.Application.__init__(self, handlers, **settings)
        self.db = scoped_session(sessionmaker(bind=engine))
        timer_job(self.db)
        self.mongo_db = MotorClient(mongo_uri)[mongo_db_name]


class Hello(BaseHandler):
    @tornado.web.asynchronous
    @tornado.web.gen.coroutine
    def get(self):
        self.write('hello,I\'m sickee,system is ok...')
        self.finish()


def main():
    # reload(sys)
    # sys.setdefaultencoding('UTF-8')
    tornado.options.parse_command_line()
    # if platform.platform().find('Linux') >= 0:
    #     start_DNS_sender()
    http_server = tornado.httpserver.HTTPServer(Application(), xheaders=True)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()


def timer_job(session):
    auth_t = auth_timer(session)

if __name__ == "__main__":
    main()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).