-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
44 lines (31 loc) · 1.1 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
# -*- coding: utf-8 -*-
import logging
from flask import Flask
from bot.api import bot
from config.extensions import csrf_protect, handler
from config.base import DevConfig
from config import commands
def create_app(config_object=DevConfig):
"""An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
:param config_object: The configuration object to use.
"""
app = Flask(__name__.split('.')[0])
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
handler.setLevel(logging.ERROR)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
app.logger.addHandler(handler)
register_commands(app)
return app
def register_extensions(app):
"""Register Flask extensions."""
csrf_protect.init_app(app)
def register_blueprints(app):
"""Register Flask blueprints."""
app.register_blueprint(bot.blueprint)
return None
def register_commands(app):
"""Register Click commands."""
app.cli.add_command(commands.test)