-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredentials.py
More file actions
25 lines (24 loc) · 877 Bytes
/
credentials.py
File metadata and controls
25 lines (24 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
# load the credentials from the .env file
def get():
"""
Load the configuration settings from the .env file.
:returns: a dictionary of credentials and configuration settings
"""
# open the .env configuration file
APP_ROOT = os.path.join(os.path.dirname(__file__)) # refers to application_top
dotenv_path = os.path.join(APP_ROOT, '.env')
# loop through each line and add to dictionary
f = open(dotenv_path, encoding='utf_8')
config = {} # empty dictionary
for line in f:
# split by =
line=line.strip() # remove line break
# remove any comment from the line
if '#' in line:
line = line[:line.find('#')]
setting = line.split('=') # split key and value apart
if len(setting) == 2:
key, value = setting
config[key] = value
return config