-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
92 lines (71 loc) · 2.43 KB
/
app.py
File metadata and controls
92 lines (71 loc) · 2.43 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import threading
import nest_asyncio
from gevent.pywsgi import WSGIServer
from flask import Flask, jsonify
from flask_cors import CORS
from flask_injector import FlaskInjector
from dependency import injector
from import_task import run_on_start
from flask_swagger import swagger
from flask_swagger_ui import get_swaggerui_blueprint
from icecream import ic
from routes import routes_api
nest_asyncio.apply()
SWAGGER_URL = '/apidocs'
SWAGGER_JSON = '/swagger.json'
class HBPBackend(Flask):
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
super(HBPBackend, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)
def create_app():
app = HBPBackend(__name__, static_url_path='')
create_cron_tab()
try:
thread = threading.Thread(target=run_on_start)
thread.start()
except Exception as ex:
ic(f'Run exception')
ic(ex)
return app
def create_cron_tab():
#cron = CronTab(user='root')
#job = cron.new(command='python import_task.py')
#job.hour.every(6)
#cron.write()
pass
app = create_app()
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
FlaskInjector(app=app, injector=injector)
@routes_api.route('/swagger.json', methods=['GET'])
def openapi():
try:
swagger_definitions = swagger(app)
swagger_definitions['title'] = 'The HippocampusHub API Documentation'
swagger_definitions['version'] = '1.0.0'
swagger_definitions['info'] = {
'title': 'The HippocampusHub API Documentation',
'version': '1.0.0',
'description': 'API documentation for the HippocampusHub portal. Visit https://www.hippocampushub.eu/ for a comprehensive view.'
}
return jsonify(swagger_definitions)
except Exception as ex:
ic(f'Run swagger exception {ex}')
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL, # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
SWAGGER_JSON,
config={ # Swagger UI config overrides
'app_name': "HBP Backend"
},
)
app.register_blueprint(routes_api)
app.register_blueprint(swaggerui_blueprint)
try:
ic(f'*******************')
ic(f'RUN APP')
ic(f'*******************')
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()
except Exception as ex:
ic(f'*******************')
ic(f'RUN EXCEPTION {ex}')
ic(f'*******************')