api_v1.4/bootstrap.py
guille 48a7f28404 Bug fix in meb session
Added new reverse method to remove dependency from openstreet maps
2023-04-12 15:26:56 -04:00

70 lines
1.9 KiB
Python

"""
Main
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author name guillermo.gutierrezmorote@concordia.ca
Project Collaborator name peteryefi@gmail.com
"""
import datetime
import flask
import yaml
from flasgger import LazyJSONEncoder, Swagger
from flask import Response
from flask_restful import Api
import threading
import hub_api.helpers.session_helper as sh
from hub_api.control.session import SessionStart, SessionEnd, KeepSessionAlive
from hub_api.control.uptime import Uptime
from hub_api.buildings.meb import Meb
from hub_api.geolocation.reverse import Reverse
sh.begin_time = datetime.datetime.now()
app = flask.Flask('cerc_api')
app.json_provider_class = LazyJSONEncoder
api = Api(app)
api.add_resource(Uptime, '/v1.4/uptime')
# Session
api.add_resource(SessionStart, '/v1.4/session/start')
api.add_resource(SessionEnd, '/v1.4/session/end')
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
# Buildings
api.add_resource(Meb, '/v1.4/buildings/meb')
# GeoLocation
api.add_resource(Reverse, '/v1.4/geolocation/reverse/<latitude>/<longitude>', endpoint='reverse')
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
swagger_config = {
"headers": [],
"specs": [
{
"endpoint": 'apispec',
"route": '/v1.4/apispec.json',
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"static_url_path": "/api/v1.4/static",
"specs_route": "/v1.4/api-docs/",
"openapi": "3.0.0"
}
try:
Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
except yaml.YAMLError as exc:
print(f'error: {exc}')
@app.route("/")
def home():
return Response(headers={'Access-Control-Allow-Origin': '*'})
sh.debug_mode = True
threading.Thread(target=sh.expired_sessions_collector, daemon=True, args="5").start()
app.run(port=15789, host="0.0.0.0", debug=sh.debug_mode)