-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (58 loc) · 1.48 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
from tornado.web import Application
from tornado.web import url
from tornado.options import define
from tornado.options import options
from tornado.options import parse_command_line
from tornado.options import parse_config_file
import tornado.ioloop
import logging
from src.handlers import *
define(
'conf',
default='/path/to/conf/file.conf',
help='location of configuration file.',
type=str
)
define(
'dev',
default=False,
help='Development toggle, enables auto reloading.',
type=bool
)
define(
'client_key',
default=None,
help='Your magazine\'s client key to the API',
type=str
)
define(
'port',
default=8888,
help='The port the app runs on.',
type=int
)
class App(Application):
def __init__(self):
handlers = [
url(r"/webhook/?$", Webhook, name="/webhook"),
]
settings = {
'client_key': options.client_key,
'debug': options.dev
}
tornado.web.Application.__init__(self, handlers, **settings)
def main():
try:
parse_config_file(options.conf)
logging.info("Loaded conf file from %s" % options.conf)
except SyntaxError as error:
logging.error("Error in conf file: %s" % error)
except IOError as error:
logging.error("Conf file missing: %s" % error)
parse_command_line()
app = App()
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()