File size: 1,722 Bytes
0b5fa25
2646146
 
c2e02ba
0b5fa25
 
 
 
2646146
0b5fa25
2646146
c2e02ba
 
 
0b5fa25
c2e02ba
2646146
c2e02ba
2646146
 
 
 
 
 
 
0b5fa25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9a5a0a3
 
3aa45c9
0b5fa25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3aa45c9
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Flask application entry point."""

from dataclasses import dataclass
import json
import logging
from flask import Flask
from flask_apscheduler import APScheduler
from asgiref.wsgi import WsgiToAsgi
from app.routes import category_bp, summary_bp

@dataclass
class Config:
    """
    Config class for application settings.

    Attributes:
        scheduler_api_enabled (bool): Indicates whether the scheduler's API is enabled.
    """
    scheduler_api_enabled: bool = True
    jobs: dict = None

    def __post_init__(self):
        if self.jobs is None:
            with open('jobs.json', 'r', encoding='utf-8') as jobs_file:
                self.jobs = json.load(jobs_file)

def create_app():
    """
    Creates and configures a Flask application with scheduled tasks.

    This function initializes a Flask application, sets up logging, 
    configures the APScheduler for scheduling tasks, and registers 
    a Blueprint for routing. It also defines a scheduled task that 
    runs daily at 16:00 server time to execute a data collection 
    process.

    Returns:
        Flask: The configured Flask application instance.
    # Create the Flask application
    """
    flask_app = Flask(__name__)
    flask_app.config.from_object(Config())
    flask_app.register_blueprint(summary_bp, url_prefix='/summary')
    flask_app.register_blueprint(category_bp)

    logging.basicConfig(
        format='%(asctime)s - %(levelname)s - %(funcName)s - %(message)s')
    logging.getLogger().setLevel(logging.ERROR)
    scheduler = APScheduler()
    scheduler.init_app(flask_app)
    scheduler.start()

    return flask_app

app = create_app()

asgi_app = WsgiToAsgi(app)

if __name__ == '__main__':
    app.run(debug=True)