From 3096e9777d89dcc44dc109620949b4be01e6f7c2 Mon Sep 17 00:00:00 2001 From: majorbruteforce Date: Sat, 1 Jun 2024 20:22:51 +0530 Subject: [PATCH] config changes --- .gitignore | 1 + __pycache__/config.cpython-310.pyc | Bin 518 -> 1061 bytes __pycache__/db.cpython-310.pyc | Bin 3766 -> 3737 bytes __pycache__/dfa.cpython-310.pyc | Bin 1600 -> 1608 bytes __pycache__/parse_message.cpython-310.pyc | Bin 1929 -> 1937 bytes config.py | 37 +++++++++++++++------- db.py | 15 +++++---- docker-compose.yml | 16 ++++++++++ 8 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 7f3a1f2..613a8f5 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ web_modules/ # dotenv environment variable files .env +.env.neon .env.development.local .env.test.local .env.production.local diff --git a/__pycache__/config.cpython-310.pyc b/__pycache__/config.cpython-310.pyc index 8160386bda6582e976b6618f0ed9c8de801e15df..09fafaf4b16c9cf34adbf2d57393f14af761a154 100644 GIT binary patch literal 1061 zcmZWn&2G~`5Z<+&)Ugxir+~yQ5{M`qk_vH(5F#X&T0tFDr$q_}%Vf7{T6;HIyG4!4 zh43Ks$SduY3l&cQCuW_rGGeWn{bqJ{{LRerO2tC3em(ziJT?&ep^W?jA9@9n`~*c1 z!4aCQcRayhYmpY~6CER>6XPqI7!-Xgkis=yJf=m8Pq$W>6weItNMTZZh!`eY6O$U$ zTw#o|X!9CRO4Q15=^C%_#Lln<{&I$FK$Q%Y0XZ3}0IJd&an3X$Xq{9cqXrr4q((~{ zRHya^HE4N*wrOR9?onrh?$fG51pAq^AKXB-$ZKP1M?53};VESoQ>?t3rNORb0Fvy0 zx`L}fWs7K^F|)za!E%TJmXRV-Sm7@?#aB=s{0RA|UG${EC}+!32ar>>Q5_WOP07k|&mW8qhQWCB z#`R?5eSbXIb%()Vx9@rG+hA`9A^maxb>DXbufOl+%tPNjkoCLMcYWV~52RT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QEFTc<=)D6{dRXV*ur$a!a|XXbMvv40X$(>^B?+q>xA5F9WmRd%w~QIT@$^i zAs{U*83heUwg1(40tZFGRZ`@5i>jP@w8}vHImyMV$So>~f%GGhk#RWYbh#dCA{IM$ zU0kO%0U9L15Fh`RE`!w{&U}Wm1=&0EpOmB^$O!+LEltb0$6ADWv2Ozfe9FCn(VlF?y{z-b}d c9tb(MJC1U^o-5@G#;7r2B#m)nvH;qjze6F^F8}}l diff --git a/__pycache__/dfa.cpython-310.pyc b/__pycache__/dfa.cpython-310.pyc index 325714f423729167559fc5234cb07d6506aa95d2..76c097d0c02a4f57d5ab06206ab067df2c0c9547 100644 GIT binary patch delta 48 zcmX@WbApFEpO=@50SMk{M{neQ!X&1vpOK%Ns-K&fm0y%pR9cdnmS2>dy7@1YGcy2N C<`3Zj delta 40 ucmX@XbAX3CpO=@50SK1dj@-!ogo#g8KO;XkRlhjDG$|u9dowGuGcy3}rVHr+ diff --git a/__pycache__/parse_message.cpython-310.pyc b/__pycache__/parse_message.cpython-310.pyc index 262d9a0067e321af83ffae8fe02af65b9b8a907f..5ca64a24e61ebf049ca9668ddd6a6fc329f3e0c7 100644 GIT binary patch delta 48 zcmeC=pUBUh&&$ij00i%}qc?I-ViYsi&&bbB)z3}L$}dVPDlJJ(%P&e!-MpId9xDJq C3J-b! delta 40 ucmbQp-^tIN&&$ij00c?*A~$kRV&v1;&&bbB)i2I3P0Gm3-n^Od9xDLTrwl>> diff --git a/config.py b/config.py index 38b3acf..09b7d94 100644 --- a/config.py +++ b/config.py @@ -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) \ No newline at end of file + 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) diff --git a/db.py b/db.py index 05dfe0c..1e39632 100644 --- a/db.py +++ b/db.py @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..198aad0 --- /dev/null +++ b/docker-compose.yml @@ -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: +