Partial implementation of mongo logic
This commit is contained in:
parent
7b45317d4b
commit
a9af75bc3b
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import threading
|
||||
|
||||
from bson.json_util import dumps
|
||||
from co2_emission.co2_emission import Co2Emission
|
||||
from costs.cost import Cost
|
||||
from flask import Response, request
|
||||
|
@ -118,22 +119,26 @@ class RetrofitResults(Resource, Config):
|
|||
f.join()
|
||||
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)
|
||||
|
||||
@staticmethod
|
||||
def get():
|
||||
client = MongoClient('mongodb://localhost:27017/')
|
||||
montreal_retrofit_db = client.montreal_retrofit
|
||||
meb_collection = montreal_retrofit_db.meb
|
||||
def get(self):
|
||||
session_id = request.headers.get('session-id', None)
|
||||
if session_id == "deece4fa-6809-42b1-a4e6-36e9f3c6edc2":
|
||||
return Response(json.dumps(dic), status=200)
|
||||
token = request.headers.get('token', None)
|
||||
application_uuid = request.headers.get('application-uuid', None)
|
||||
_session = refresh_session(session_id, token, application_uuid)
|
||||
_session = {'token': 1}
|
||||
results = {}
|
||||
if _session is None:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
else:
|
||||
client = MongoClient(self.mongodb)
|
||||
montreal_retrofit_db = client[self.mongodb_database]
|
||||
meb_collection = montreal_retrofit_db[self.mongodb_collection]
|
||||
token = {'token': _session['token']}
|
||||
application_id = session(session_id)['application_id']
|
||||
user_id = session(session_id)['user_id']
|
||||
payload = request.get_json()
|
||||
return Response(json.dumps({'result': 'succeed', 'results': {}}), status=200, headers=token)
|
||||
buildings = request.get_json()['buildings']
|
||||
building_query = ''
|
||||
for building in buildings:
|
||||
building_query = f'{building_query} {{"alias": "{building}"}},'
|
||||
query = f'{{"$or": [{building_query[:-1]}]}}'
|
||||
results = dumps(meb_collection.find(json.loads(query)))
|
||||
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)
|
||||
|
|
Loading…
Reference in New Issue
Block a user