flirror/__init__.py
def create_app(
    config: Optional[Dict] = None, jinja_options: Optional[Any] = None
) -> Flirror:
    """
    Load configuration file and initialize flirror app with necessary
    components like database and modules.
    """

    # TODO (felix): Find a better way to overwrite the jinja_options for the unit tests.
    # As stated in https://github.com/pallets/flask/blob/38eb5d3b49d628785a470e2e773fc5ac82e3c8e4/src/flask/app.py#L679
    # overwriting the jinja_options should be done as early as possible.
    app = Flirror(__name__)

    # Overwrite or set additional jinja_options. This is currently only used for
    # validating the templates in the unit tests.
    if jinja_options is not None:
        app.jinja_options = {**app.jinja_options, **jinja_options}

    # Load the config from the python file specified in the env vars and
    # overwrite values that are provided directly via arguments.
    # TODO (felix): Add default settings, once we have some
    # TODO (felix): Validate config?
    app.config.from_envvar(FLIRROR_SETTINGS_ENV)
    if config is not None:
        app.config.from_mapping(config)

    app.secret_key = app.config["SECRET_KEY"]

    # Using the URL prefix is a good way so modules cannot conflict with each other
    # TODO (felix): Auto look-up for modules by name and modules specified in the
    # config file or something like
    # https://packaging.python.org/guides/creating-and-discovering-plugins/
    # TODO (felix): Prefix each module's URL with its name to avoid name clashes
    # between modules and all can simply use the same url_rule ("/").
    # Register all standard modules
    for module in [
        clock_module,
        weather_module,
        calendar_module,
        newsfeed_module,
        stocks_module,
    ]:
        app.register_module(module)

    # Discover and register custom plugins
    app.register_plugins()

    # Connect to the sqlite database
    # TODO (felix): Maybe we could drop the 'create_db' here?
    # Usually, it should be sufficient, when the crawler creates the database. If it
    # is not created here, we should just provide some message to start the crawler.
    db = create_database_and_entities(
        provider="sqlite", filename=app.config["DATABASE_FILE"], create_db=True
    )

    # Store the dabase connection in flask's extensions dictionary.
    if not hasattr(app, "extensions"):
        app.extensions = {}
    if "database" not in app.extensions:
        app.extensions["database"] = db

    return app

    Load configuration file and initialize flirror app with necessary
    components like database and modules.
    
Load configuration file and initialize flirror app with necessary
components like database and modules.
Load configuration file and initialize flirror app with necessary components like database and modules .
def create_app(
    config: Optional[Dict] = None, jinja_options: Optional[Any] = None
) -> Flirror:
    app = Flirror(__name__)
    if jinja_options is not None:
        app.jinja_options = {**app.jinja_options, **jinja_options}
    app.config.from_envvar(FLIRROR_SETTINGS_ENV)
    if config is not None:
        app.config.from_mapping(config)
    app.secret_key = app.config["SECRET_KEY"]
    for module in [
        clock_module,
        weather_module,
        calendar_module,
        newsfeed_module,
        stocks_module,
    ]:
        app.register_module(module)
    app.register_plugins()
    db = create_database_and_entities(
        provider="sqlite", filename=app.config["DATABASE_FILE"], create_db=True
    )
    if not hasattr(app, "extensions"):
        app.extensions = {}
    if "database" not in app.extensions:
        app.extensions["database"] = db
    return app
def create_app ( config : Optional [ Dict ] = None , jinja_options : Optional [ Any ] = None ) -> Flirror : app = Flirror ( __name__ ) if jinja_options is not None : app . jinja_options = { ** app . jinja_options , ** jinja_options } app . config . from_envvar ( FLIRROR_SETTINGS_ENV ) if config is not None : app . config . from_mapping ( config ) app . secret_key = app . config [ "SECRET_KEY" ] for module in [ clock_module , weather_module , calendar_module , newsfeed_module , stocks_module , ] : app . register_module ( module ) app . register_plugins ( ) db = create_database_and_entities ( provider = "sqlite" , filename = app . config [ "DATABASE_FILE" ] , create_db = True ) if not hasattr ( app , "extensions" ) : app . extensions = { } if "database" not in app . extensions : app . extensions [ "database" ] = db return app
Load configuration file and initialize flirror app with necessary
components like database and modules.
Load configuration file and initialize flirror app with necessary components like database and modules .
"""
    Load configuration file and initialize flirror app with necessary
    components like database and modules.
    """ # TODO (felix): Find a better way to overwrite the jinja_options for the unit tests. # As stated in https://github.com/pallets/flask/blob/38eb5d3b49d628785a470e2e773fc5ac82e3c8e4/src/flask/app.py#L679 # overwriting the jinja_options should be done as early as possible. # Overwrite or set additional jinja_options. This is currently only used for # validating the templates in the unit tests. # Load the config from the python file specified in the env vars and # overwrite values that are provided directly via arguments. # TODO (felix): Add default settings, once we have some # TODO (felix): Validate config? # Using the URL prefix is a good way so modules cannot conflict with each other # TODO (felix): Auto look-up for modules by name and modules specified in the # config file or something like # https://packaging.python.org/guides/creating-and-discovering-plugins/ # TODO (felix): Prefix each module's URL with its name to avoid name clashes # between modules and all can simply use the same url_rule ("/"). # Register all standard modules # Discover and register custom plugins # Connect to the sqlite database # TODO (felix): Maybe we could drop the 'create_db' here? # Usually, it should be sufficient, when the crawler creates the database. If it # is not created here, we should just provide some message to start the crawler. # Store the dabase connection in flask's extensions dictionary.
config
Optional[Dict]
jinja_options
Optional[Any]