56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import os
|
|
from flask import Flask
|
|
from flask_bootstrap import Bootstrap5
|
|
from datetime import datetime
|
|
|
|
from app.views import register_views
|
|
from app.api import register_api
|
|
from app.config import load_config
|
|
from app.filters import register_filters
|
|
from app.tasks import celery
|
|
|
|
from app.logging_config import init_logger
|
|
|
|
def create_app(config=None):
|
|
app = Flask(__name__)
|
|
|
|
if config is None:
|
|
config = load_config()
|
|
app.config.update(config)
|
|
|
|
os.environ['TZ'] = 'UTC'
|
|
|
|
app.config['SECRET_KEY'] = config['DEFAULT']['SECRET_KEY']
|
|
|
|
# Move bootstrap settings to root level
|
|
for key, value in config.get('BOOTSTRAP', {}).items():
|
|
app.config[key.upper()] = value
|
|
|
|
# Initialize Celery
|
|
celery.conf.update(app.config)
|
|
|
|
bootstrap = Bootstrap5(app)
|
|
|
|
# Store the entire config in Flask app
|
|
app.config.update(config)
|
|
|
|
# Initialize other settings
|
|
app.config['SCRAPING_ACTIVE'] = False
|
|
app.config['SCRAPING_THREAD'] = None
|
|
app.config['DATA_FILE_NAME'] = None
|
|
app.config['LOG_FILE_NAME'] = "log/" + datetime.now().strftime('%Y-%m-%d-%H-%M') + '.log'
|
|
|
|
# Initialize logging
|
|
app.logger = init_logger(app.config)
|
|
|
|
# Register routes
|
|
register_views(app)
|
|
register_api(app)
|
|
register_filters(app)
|
|
|
|
@app.context_processor
|
|
def inject_main_config():
|
|
main_config = app.config.get('MAIN', {})
|
|
return dict(main_config=main_config)
|
|
|
|
return app |