api_v1.4/hub_api/config.py

44 lines
1.6 KiB
Python

"""
Config
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Peter Yefi peteryefi@gmail.com
"""
import os
from hub.exports.db_factory import DBFactory as CityExportFactory
from hub.imports.db_factory import DBFactory
from hub.imports.user_factory import UserFactory
from hub.exports.user_factory import UserFactory as ExUserFactory
class Config:
def __init__(self):
db_name = None
app_env = None
if os.getenv("FLASK_DEBUG") == 'production':
db_name = 'hub_prod'
app_env = 'PROD'
elif os.getenv("FLASK_DEBUG") == 'testing':
db_name = 'hub_test'
app_env = 'TEST'
self.export_db_factory = CityExportFactory(db_name=db_name, app_env=app_env,
dotenv_path="{}/.env".format(os.path.expanduser('~')))
self.import_db_factory = DBFactory(db_name=db_name, app_env=app_env,
dotenv_path="{}/.env".format(os.path.expanduser('~')))
self.user_factory = UserFactory(db_name=db_name, app_env=app_env,
dotenv_path="{}/.env".format(os.path.expanduser('~')))
self.ex_user_factory = ExUserFactory(db_name=db_name, app_env=app_env,
dotenv_path="{}/.env".format(os.path.expanduser('~')))
def get_city(self, city_id):
return self.export_db_factory.get_city(city_id)
def get_city_by_name(self, city_name):
return self.export_db_factory.get_city_by_name(city_name)
def get_city_by_user(self, user_id):
return self.export_db_factory.get_city_by_user(user_id)