-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
52 lines (33 loc) · 828 Bytes
/
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
import api
import logging
import yaml
from tv7 import TV7
from flask import Flask
from flask_cors import CORS
from flask.logging import default_handler
import sys
def read_config(file):
with open(file) as conf:
c = yaml.load(conf, Loader=yaml.FullLoader)
if not 'port' in c:
c['port'] = 80
return c
def setup(cfg):
tv7 = TV7(config=cfg)
tv7.update()
api.tv7 = tv7
setup_app = Flask(__name__)
CORS(setup_app)
setup_app.register_blueprint(api.bp)
return setup_app
if __name__ == "__main__":
if len(sys.argv) > 1:
config_file = sys.argv[1]
else:
config_file = 'config.yml'
logging.basicConfig()
root = logging.getLogger()
root.setLevel(logging.INFO)
config = read_config(config_file)
app = setup(config)
app.run(host='0.0.0.0', port=int(config['port']))