Muhammad Abdur Rahman Saad
commited on
Commit
·
123f3e2
1
Parent(s):
f100a8c
refactor code according to comments
Browse files- app.py +18 -8
- requirements.txt +2 -1
- routes/__init__.py +6 -0
- routes.py → routes/main.py +3 -3
app.py
CHANGED
@@ -1,21 +1,28 @@
|
|
|
|
1 |
from flask import Flask
|
2 |
from flask_apscheduler import APScheduler
|
3 |
-
from
|
|
|
|
|
4 |
from main import main as data_collection_main
|
5 |
|
6 |
class Config:
|
7 |
-
SCHEDULER_API_ENABLED = True # Enables the scheduler's API
|
8 |
|
9 |
def create_app():
|
10 |
# Create the Flask application
|
11 |
-
|
12 |
|
13 |
# Load config for APScheduler
|
14 |
-
|
15 |
|
16 |
-
# Register our Blueprint
|
17 |
-
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# Initialize the APScheduler
|
20 |
scheduler = APScheduler()
|
21 |
scheduler.init_app(app)
|
@@ -34,7 +41,10 @@ def create_app():
|
|
34 |
|
35 |
return app
|
36 |
|
|
|
|
|
|
|
|
|
37 |
if __name__ == '__main__':
|
38 |
# Create the Flask app and run it
|
39 |
-
|
40 |
-
app.run(debug=True, port=5000)
|
|
|
1 |
+
import logging
|
2 |
from flask import Flask
|
3 |
from flask_apscheduler import APScheduler
|
4 |
+
from asgiref.wsgi import WsgiToAsgi
|
5 |
+
|
6 |
+
from routes.main import bp
|
7 |
from main import main as data_collection_main
|
8 |
|
9 |
class Config:
|
10 |
+
SCHEDULER_API_ENABLED = True # Enables the scheduler's API
|
11 |
|
12 |
def create_app():
|
13 |
# Create the Flask application
|
14 |
+
flask_app = Flask(__name__)
|
15 |
|
16 |
# Load config for APScheduler
|
17 |
+
flask_app.config.from_object(Config())
|
18 |
|
19 |
+
# Register our Blueprint
|
20 |
+
flask_app.register_blueprint(bp)
|
21 |
|
22 |
+
logging.basicConfig(
|
23 |
+
format='%(asctime)s - %(levelname)s - %(funcName)s - %(message)s')
|
24 |
+
logging.getLogger().setLevel(logging.ERROR)
|
25 |
+
|
26 |
# Initialize the APScheduler
|
27 |
scheduler = APScheduler()
|
28 |
scheduler.init_app(app)
|
|
|
41 |
|
42 |
return app
|
43 |
|
44 |
+
app = create_app()
|
45 |
+
|
46 |
+
asgi_app = WsgiToAsgi(app)
|
47 |
+
|
48 |
if __name__ == '__main__':
|
49 |
# Create the Flask app and run it
|
50 |
+
app.run()
|
|
requirements.txt
CHANGED
@@ -196,5 +196,6 @@ wrapt==1.16.0
|
|
196 |
yarl==1.9.4
|
197 |
prefect==2.20.2
|
198 |
pycryptodome==3.21.0
|
|
|
199 |
flask
|
200 |
-
flask_apscheduler
|
|
|
196 |
yarl==1.9.4
|
197 |
prefect==2.20.2
|
198 |
pycryptodome==3.21.0
|
199 |
+
asgiref==3.8.1
|
200 |
flask
|
201 |
+
flask_apscheduler
|
routes/__init__.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
This module sets up the main Blueprint for the Flask application.
|
3 |
+
"""
|
4 |
+
from flask import Blueprint
|
5 |
+
|
6 |
+
bp = Blueprint("data", __name__)
|
routes.py → routes/main.py
RENAMED
@@ -1,7 +1,7 @@
|
|
1 |
from flask import Blueprint, jsonify
|
2 |
-
from main import main as
|
3 |
|
4 |
-
|
5 |
|
6 |
@bp.route('/trigger-data-collection', methods=['GET'])
|
7 |
def trigger_data_collection():
|
@@ -10,5 +10,5 @@ def trigger_data_collection():
|
|
10 |
|
11 |
HTTP Method: GET (you can switch to POST if you prefer).
|
12 |
"""
|
13 |
-
|
14 |
return jsonify({"message": "Data collection triggered successfully"}), 200
|
|
|
1 |
from flask import Blueprint, jsonify
|
2 |
+
from main import main as data_collection
|
3 |
|
4 |
+
from . import bp
|
5 |
|
6 |
@bp.route('/trigger-data-collection', methods=['GET'])
|
7 |
def trigger_data_collection():
|
|
|
10 |
|
11 |
HTTP Method: GET (you can switch to POST if you prefer).
|
12 |
"""
|
13 |
+
data_collection() # This calls the Prefect flow that orchestrates data collection
|
14 |
return jsonify({"message": "Data collection triggered successfully"}), 200
|