-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathapp.py
49 lines (37 loc) · 1.57 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
import os.path
from flask import Flask
from flask_apscheduler import APScheduler
from flask_login import LoginManager
from flask_wtf import CSRFProtect
from utils.phrases_dict import phrases_dict_init
from tts_app import frontend, voice_api, auth, admin
from utils.config_manager import global_config
app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'templates'),
static_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'static'))
app.config.from_pyfile("config.py")
app.config.update(global_config)
phrases_dict_init()
if app.config.get("IS_ADMIN_ENABLED", False):
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'auth.login'
csrf = CSRFProtect(app)
@login_manager.user_loader
def load_user(user_id):
users = app.config["users"]["admin"]
for user in users.values():
if user.get_id() == user_id:
return user
return None
# Initialize scheduler
scheduler = APScheduler()
scheduler.init_app(app)
if app.config.get("CLEAN_INTERVAL_SECONDS", 3600) > 0:
scheduler.start()
app.register_blueprint(frontend, url_prefix='/')
app.register_blueprint(voice_api, url_prefix='/voice')
if app.config.get("IS_ADMIN_ENABLED", False):
app.register_blueprint(auth, url_prefix=app.config.get("ADMIN_ROUTE", "/admin"))
app.register_blueprint(admin, url_prefix=app.config.get("ADMIN_ROUTE", "/admin"))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=app.config.get("PORT", 23456), debug=app.config.get("DEBUG", False))