42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
|
import configparser
|
||
|
import logging
|
||
|
import sys
|
||
|
from os import environ
|
||
|
from flask import Flask
|
||
|
from . import twitch
|
||
|
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
blueprints = {
|
||
|
"twitch": twitch,
|
||
|
}
|
||
|
|
||
|
|
||
|
def create_app():
|
||
|
"""Read the app configuration and instantiate service blueprints."""
|
||
|
debug = environ.get("FLASK_ENV", "production") == "development"
|
||
|
level = logging.DEBUG if debug else logging.INFO
|
||
|
logging.basicConfig(level=level)
|
||
|
|
||
|
config_path = environ.get("FEEDLEWARE_CONFIG")
|
||
|
|
||
|
if not config_path:
|
||
|
print(
|
||
|
"Please set the FEEDLEWARE_CONFIG environment variable",
|
||
|
file=sys.stderr,
|
||
|
)
|
||
|
sys.exit(1)
|
||
|
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read(config_path)
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
for section in config.sections():
|
||
|
if section in blueprints:
|
||
|
blueprint = blueprints[section].create_blueprint(config[section])
|
||
|
app.register_blueprint(blueprint, url_prefix="/" + section)
|
||
|
else:
|
||
|
logger.warning("Unknown service '%s'", section)
|
||
|
|
||
|
return app
|