Skip to content

Commit

Permalink
Added env variable login
Browse files Browse the repository at this point in the history
  • Loading branch information
Kandeel4411 committed May 15, 2019
1 parent 4c62f2b commit 6f0bdd2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
17 changes: 9 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions etc/config.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<<<<<<< HEAD
[Login]
client_id = []
client_secret = []
user_agent = RedditWallpaperBotv1

=======
>>>>>>> 3b567e5... Added env variable login
[Logging]
filename=debug.log
filemode=w
Expand Down
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down

0 comments on commit 6f0bdd2

Please sign in to comment.