added checking for environment variables
This commit is contained in:
@@ -3,6 +3,7 @@ from dotenv import load_dotenv
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
# load default values
|
# load default values
|
||||||
@@ -21,6 +22,20 @@ def connect(
|
|||||||
"""
|
"""
|
||||||
Connect to MongoDB database and return collection.
|
Connect to MongoDB database and return collection.
|
||||||
"""
|
"""
|
||||||
|
# load environment variables
|
||||||
|
load_dotenv()
|
||||||
|
ip_addr = os.getenv(
|
||||||
|
'DB_IP_ADDRESS',
|
||||||
|
default=DB_IP_ADDRESS
|
||||||
|
)
|
||||||
|
db_name = os.getenv(
|
||||||
|
'DB_NAME',
|
||||||
|
default=DB_NAME
|
||||||
|
)
|
||||||
|
collection_name = os.getenv(
|
||||||
|
'DB_COLLECTION_NAME',
|
||||||
|
default=DB_COLLECTION_NAME
|
||||||
|
)
|
||||||
# connect to database
|
# connect to database
|
||||||
client: MongoClient = MongoClient(ip_addr)
|
client: MongoClient = MongoClient(ip_addr)
|
||||||
db = client[db_name]
|
db = client[db_name]
|
||||||
|
|||||||
Reference in New Issue
Block a user