#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/10/28 12:11 # @File : __init__.py # @Description : """ import os from flask import Flask from application.extensions import init_plugs from application.views import init_views from application.script import init_script from application.utils import make_celery from celery.schedules import crontab def create_app() -> Flask: """ This function creates and initializes a new Flask application. :return: A new instance of a Flask application. """ # Determine the path of the application root directory app_root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".")) # Create a new Flask application instance app = Flask(app_root_path) # Initialize various plugins for the application. # This could include things like database connectors, authentication systems, etc. init_plugs(app) celery = make_celery(app) celery.conf.update(app.config) @celery.task(bind=True) def update_database(self): # Add your database operations here print("update database") celery.conf.beat_schedule = { 'update-database-every-minute': { 'task': 'application.__init__.update_database', 'schedule': crontab(minute='*') # Execute every minute } } app.celery = celery # Register the routes that this application will respond to. # This includes both the route URLs and the handlers for each route. init_views(app) # Register any scripts or commands that can be run from the command line. # This could include data migration scripts, administrative tasks, etc. init_script(app) # Return the fully initialized Flask application return app