From 6f0bdd27f0b2c3d61928fda62ff0e5f9c4132e06 Mon Sep 17 00:00:00 2001 From: abdo Date: Tue, 9 Apr 2019 05:11:03 +0200 Subject: [PATCH] Added env variable login --- bot.py | 17 +++++++++-------- etc/config.ini | 3 +++ main.py | 7 +++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index fc71989..490a663 100644 --- a/bot.py +++ b/bot.py @@ -9,13 +9,12 @@ logger = logging.getLogger(__name__) -def get_reddit(login): - """Input: Dict with client_id and client_secret """ +def get_reddit(client_id,client_secret,user_agent): try: reddit = praw.Reddit( - client_id=login["client_id"], - client_secret=login["client_secret"], - user_agent=login["user_agent"] + client_id=client_id, + client_secret=client_secret, + user_agent=user_agent ) except Exception as e: logger.exception(f"{e}") @@ -50,9 +49,11 @@ def get_picture_post(subreddit_sort): try: for submission in subreddit_sort: # Is an image tagged post which isn't a gif - if hasattr(submission, "post_hint")\ - and submission.post_hint == "image"\ - and os.path.splitext(submission.url)[1] != ".gif": + if ( + hasattr(submission, "post_hint") + and submission.post_hint == "image" + and os.path.splitext(submission.url)[1] != ".gif" + ): logger.info(f"{submission} Has Picture ") logger.debug("Finished Iteration") return submission diff --git a/etc/config.ini b/etc/config.ini index f276765..3389861 100644 --- a/etc/config.ini +++ b/etc/config.ini @@ -1,8 +1,11 @@ +<<<<<<< HEAD [Login] client_id = [] client_secret = [] user_agent = RedditWallpaperBotv1 +======= +>>>>>>> 3b567e5... Added env variable login [Logging] filename=debug.log filemode=w diff --git a/main.py b/main.py index edd2623..e300597 100644 --- a/main.py +++ b/main.py @@ -37,8 +37,11 @@ def main(): """) # Create reddit object - login_config = config["Login"] - reddit = bot.get_reddit(login=login_config) + reddit = bot.get_reddit( + client_id=os.environ["client_id"], + client_secret=os.environ["client_secret"], + user_agent=os.environ["user_agent"] + ) # Getting user-specified subreddit subreddit_name = input("Enter the subreddit you want to access: ")