Partial implementation of mongo logic
This commit is contained in:
parent
bb0bd4d31f
commit
7b45317d4b
@ -7,7 +7,7 @@ import distutils
|
||||
import os
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import hub.helpers.dictionaries
|
||||
from hub.persistence.db_control import DBControl
|
||||
from hub.persistence.repository import Repository
|
||||
@ -20,11 +20,14 @@ class Config:
|
||||
dotenv_path = "{}/.local/etc/hub_api/.env".format(os.path.expanduser('~'))
|
||||
if platform.system() == 'Linux':
|
||||
dotenv_path = Path(dotenv_path).resolve()
|
||||
|
||||
environment = 'PROD'
|
||||
database_name = 'montreal_retrofit'
|
||||
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._repository = Repository(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._database_name = os.getenv(f'{environment}_DB_NAME')
|
||||
load_dotenv(dotenv_path=dotenv_path)
|
||||
self._mongodb = os.getenv(f'{environment}_MONGO_DB')
|
||||
self._mongodb_database = os.getenv(f'{environment}_MONGO_DB_DATABASE')
|
||||
self._mongodb_collection = os.getenv(f'{environment}_MONGO_DB_COLLECTION')
|
||||
self._database = DBControl(db_name=self._database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._repository = Repository(db_name=self._database_name, app_env=environment, dotenv_path=dotenv_path)
|
||||
self._energy_systems_catalog = EnergySystemsCatalogFactory('montreal_custom').catalog
|
||||
self._dictionaries = {
|
||||
'pluto': hub.helpers.dictionaries.Dictionaries().pluto_function_to_hub_function,
|
||||
@ -63,6 +66,13 @@ class Config:
|
||||
return distutils.spawn.find_executable('sra')
|
||||
|
||||
@property
|
||||
def base_uri(self):
|
||||
return self._base_uri
|
||||
def mongodb(self):
|
||||
return self._mongodb
|
||||
|
||||
@property
|
||||
def mongodb_database(self):
|
||||
return self._mongodb_database
|
||||
|
||||
@property
|
||||
def mongodb_collection(self):
|
||||
return self._mongodb_collection
|
||||
|
@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import json
|
||||
import threading
|
||||
|
||||
@ -6,6 +5,7 @@ from co2_emission.co2_emission import Co2Emission
|
||||
from costs.cost import Cost
|
||||
from flask import Response, request
|
||||
from flask_restful import Resource
|
||||
from pymongo import MongoClient
|
||||
|
||||
from hub_api.config import Config
|
||||
from hub_api.helpers.session_helper import session, refresh_session
|
||||
@ -117,3 +117,23 @@ class RetrofitResults(Resource, Config):
|
||||
for f in t:
|
||||
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
|
||||
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)
|
||||
if _session is None:
|
||||
return Response(json.dumps({'error': 'unauthorized'}), status=403)
|
||||
else:
|
||||
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)
|
||||
|
@ -29,4 +29,7 @@ python-dotenv
|
||||
mapbox_earcut
|
||||
cerc-costs
|
||||
cerc-co2-emission
|
||||
werkzeug
|
||||
werkzeug
|
||||
sqlalchemy
|
||||
pathlib
|
||||
pymongo
|
Loading…
Reference in New Issue
Block a user