-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
30 lines (25 loc) · 1.09 KB
/
config.py
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
26
27
28
29
30
import os
from dotenv import load_dotenv, find_dotenv
SECRET_KEY = os.urandom(32)
# Grabs the folder where the script runs. For debugging purposes.
basedir = os.path.abspath(os.path.dirname(__file__))
# Database credentials and set up
# N.B. A user password is required, otherwise, you get a runtime exception
# when programmatically opening the Postgres database.
ENV_FILE = find_dotenv()
if ENV_FILE:
load_dotenv(ENV_FILE)
try:
db_user = os.environ['ESPRESSO_DB_USER']
db_password = os.environ['ESPRESSO_DB_PASSWORD']
db_host = os.environ['ESPRESSO_DB_HOST']
db_database_name = os.environ['ESPRESSO_DB_DATABASE_NAME']
except KeyError as ex:
print("The espresso app requires four environment variables: " \
"ESPRESSO_DB_USER ESPRESSO_DB_PASSWORD ESPRESSO_DB_HOST ESPRESSO_DB_DATABASE_NAME")
print(f"Environment variable {ex.args[0]} is missing")
print(f"Please set {ex.args[0]} and restart the app")
raise
db_url = f"postgres+psycopg2://{db_user}:{db_password}@{db_host}/{db_database_name}"
SQLALCHEMY_DATABASE_URI = db_url
SQLALCHEMY_TRACK_MODIFICATIONS = False