From f118861c0517425a55b7bc9e50e8f371c417e2b1 Mon Sep 17 00:00:00 2001 From: jmueller Date: Thu, 14 Dec 2023 18:16:22 +0100 Subject: [PATCH] Implemented Env-Change --- Dockerfile | 6 ++++++ main.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e81870f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.10 +LABEL authors="jmueller" + +ADD main.py . +RUN pip install py-cord mariadb python-dotenv +CMD ["python", "./main.py"] diff --git a/main.py b/main.py index 83438f0..e3edc71 100644 --- a/main.py +++ b/main.py @@ -6,10 +6,15 @@ import mariadb import sys from discord import default_permissions -load_dotenv() # load all the variables from the env file +configfile = "config.json" +if os.path.exists(configfile): + with open('config.json') as user_file: + config = json.loads(user_file.read()) +else: + config = {"db_user": os.environ["db_user"], "db_password": os.environ["db_password"], "db_host": os.environ["db_host"], "db_pass": os.environ["db_pass"]} -with open('config.json') as user_file: - config = json.loads(user_file.read()) +if os.path.exists(".env"): + load_dotenv() def connect_db():