diff --git a/src/config/reddit/config_gen.py b/src/config/reddit/config_gen.py index b846ed3..ce01d54 100644 --- a/src/config/reddit/config_gen.py +++ b/src/config/reddit/config_gen.py @@ -1,4 +1,3 @@ -import configparser import praw import sys import os @@ -6,9 +5,6 @@ from prawcore import ResponseException from ..common_config import ENV_FILE -# create configparser object -config_file = configparser.ConfigParser() -config_file.optionxform = str def config_gen(): @@ -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() @@ -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()