2023-02-24 16:57:51 -05:00
|
|
|
import json
|
|
|
|
from flask import Response, request
|
|
|
|
from flask_restful import Resource
|
|
|
|
|
|
|
|
from hub_api.helpers.session_helper import active_session, refresh_session
|
|
|
|
from hub_api.config import Config
|
|
|
|
|
2023-03-10 10:15:20 -05:00
|
|
|
class Meb(Resource, Config):
|
2023-02-24 16:57:51 -05:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
2023-03-10 10:15:20 -05:00
|
|
|
def get(self):
|
|
|
|
"""
|
2023-02-24 16:57:51 -05:00
|
|
|
API call for requesting a specified list of enriched buildings
|
2023-03-10 10:15:20 -05:00
|
|
|
"""
|
2023-02-24 16:57:51 -05:00
|
|
|
session_id = request.headers.get('session_id', None)
|
|
|
|
token = request.headers.get('token', None)
|
|
|
|
application_uuid = request.headers.get('application_uuid', None)
|
|
|
|
|
2023-03-10 10:15:20 -05:00
|
|
|
if active_session(session_id, token, application_uuid):
|
2023-03-06 10:56:46 -05:00
|
|
|
refresh_session(session_id, token, application_uuid)
|
|
|
|
payload = request.get_json()
|
|
|
|
buildings = {}
|
2023-02-24 16:57:51 -05:00
|
|
|
|
2023-03-06 10:56:46 -05:00
|
|
|
for city in payload['cities']:
|
|
|
|
buildings[city] = {}
|
|
|
|
for building in payload['cities'][city]:
|
|
|
|
buildings[city][building] = self.export_db_factory.building_info(building, city)
|
2023-02-24 16:57:51 -05:00
|
|
|
|
2023-03-10 10:15:20 -05:00
|
|
|
# TODO: finish formatting buildings to match swagger documentation
|
2023-03-06 10:56:46 -05:00
|
|
|
# and change export_db_factory.building_info to use MEB database
|
|
|
|
# call when ready
|
2023-02-24 16:57:51 -05:00
|
|
|
|
2023-03-06 10:56:46 -05:00
|
|
|
return Response(json.dumps({'result': 'succeed', 'results': buildings}), status=200)
|
2023-03-10 10:15:20 -05:00
|
|
|
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|