Skip to content

Commit

Permalink
config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
majorbruteforce committed Jun 1, 2024
1 parent a88cb73 commit 3096e97
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ web_modules/

# dotenv environment variable files
.env
.env.neon
.env.development.local
.env.test.local
.env.production.local
Expand Down
Binary file modified __pycache__/config.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/db.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/dfa.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/parse_message.cpython-310.pyc
Binary file not shown.
37 changes: 26 additions & 11 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import os
import sys
from dotenv import load_dotenv

load_dotenv()
def load_environment(env):
if env == 'neon':
dotenv_path = '.env.neon'
elif env == 'local':
dotenv_path = '.env.local'
else:
raise ValueError("Environment not recognized. Use 'neon' or 'local'.")

load_dotenv(dotenv_path)

# Determine the environment to load
environment = os.getenv('ENVIRONMENT') or (sys.argv[1] if len(sys.argv) > 1 else 'local')
load_environment(environment)

DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
WATCHED_CHANNEL_ID = int(os.getenv('WATCHED_CHANNEL_ID'))
DATABASE_NAME=os.getenv('DATABASE_NAME')
DATABASE_USER=os.getenv('DATABASE_USER')
DATABASE_PASSWORD=os.getenv('DATABASE_PASSWORD')
DATABASE_HOST=os.getenv('DATABASE_HOST')
DATABASE_NAME = os.getenv('DATABASE_NAME')
DATABASE_USER = os.getenv('DATABASE_USER')
DATABASE_PASSWORD = os.getenv('DATABASE_PASSWORD')
DATABASE_HOST = os.getenv('DATABASE_HOST')


if __name__ == "__main__":
print(DISCORD_TOKEN)
print(WATCHED_CHANNEL_ID)
print(DATABASE_NAME)
print(DATABASE_USER)
print(DATABASE_PASSWORD)
print(DATABASE_HOST)
print("Using environment:", environment)
print("DISCORD_TOKEN:", DISCORD_TOKEN)
print("WATCHED_CHANNEL_ID:", WATCHED_CHANNEL_ID)
print("DATABASE_NAME:", DATABASE_NAME)
print("DATABASE_USER:", DATABASE_USER)
print("DATABASE_PASSWORD:", DATABASE_PASSWORD)
print("DATABASE_HOST:", DATABASE_HOST)
15 changes: 8 additions & 7 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import datetime
def connect_to_database():
try:
conn = psycopg2.connect('postgresql://synergylabs_owner:ZYz8PqkvE9Ma@ep-snowy-sunset-a14d2ehb.ap-southeast-1.aws.neon.tech/Chowky?sslmode=require')
# conn = psycopg2.connect(
# dbname=DATABASE_NAME,
# user=DATABASE_USER,
# password=DATABASE_PASSWORD,
# host=DATABASE_HOST
# )
# conn = psycopg2.connect('postgresql://synergylabs_owner:ZYz8PqkvE9Ma@ep-snowy-sunset-a14d2ehb.ap-southeast-1.aws.neon.tech/Chowky?sslmode=require')
conn = psycopg2.connect(
dbname=DATABASE_NAME,
user=DATABASE_USER,
password=DATABASE_PASSWORD,
host=DATABASE_HOST,
port=5432
)
print("Connection to the database was successful")
return conn
except psycopg2.Error as e:
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
postgres:
image: postgres:latest
container_name: chowidaar_db
env_file:
- .env.local
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:

0 comments on commit 3096e97

Please sign in to comment.