Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config_gen.py #190

Merged
merged 1 commit into from
Nov 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()