Skip to content

Commit

Permalink
Merge pull request #190 from igosad/master
Browse files Browse the repository at this point in the history
Update config_gen.py
  • Loading branch information
MrPowerScripts authored Nov 27, 2021
2 parents db5ab43 + f24bb54 commit ccc86c8
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/config/reddit/config_gen.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import configparser
import praw
import sys
import os
from logs.logger import log
from prawcore import ResponseException
from ..common_config import ENV_FILE

# create configparser object
config_file = configparser.ConfigParser()
config_file.optionxform = str


def config_gen():
Expand All @@ -25,8 +21,8 @@ def config_gen():
username=USERNAME,
password=PASSWORD
)
# CHECK IF CREDENTIALS ARE CORRECT

# CHECK IF CREDENTIALS ARE CORRECT
def authenticated(reddit):
try:
reddit.user.me()
Expand All @@ -35,22 +31,18 @@ def authenticated(reddit):
else:
return True

config_file["REDDIT_AUTH"] = {
"bot_reddit_client_id": f'"{CLIENT_ID}"',
"bot_reddit_client_secret": f'"{CLIENT_SECRET}"',
"bot_reddit_password": f'"{PASSWORD}"',
"bot_reddit_username": f'"{USERNAME}"',
}

# SAVE CONFIG FILE
if authenticated(reddit) is True:
if authenticated(reddit):
with open(ENV_FILE, "w") as file_object:
config_file.write(file_object, space_around_delimiters=False)
print("Config file '.env' created. Please re-run the bot")
sys.exit()
file_object.write(f'bot_reddit_client_id="{CLIENT_ID}"\n')
file_object.write(f'bot_reddit_client_secret="{CLIENT_SECRET}"\n')
file_object.write(f'bot_reddit_password="{PASSWORD}"\n')
file_object.write(f'bot_reddit_username="{USERNAME}"\n')
print("Config file '.env' created. Please re-run the bot")
sys.exit()

else:
print(' WRONG CREDENTIALS ! ')
print(' PLEASE INPUT CORRECT CREDENTIALS .')
print('WRONG CREDENTIALS!! TRY AGAIN')
config_gen()

0 comments on commit ccc86c8

Please sign in to comment.