Reddit credentials validation in screenshot_downloader.py

# Description

The Playwright locator timed out in line 175 without letting the user know why. The browser failed to log me in to Reddit using the incorrect credentials, which prevented it from accessing the desired post. This fix should be a much more user-friendly approach.

# Issue Fixes

https://github.com/elebumm/RedditVideoMakerBot/issues/1596

None

# Checklist:

- [] I am pushing changes to the **develop** branch
- [] I am using the recommended development environment
- [] I have performed a self-review of my own code
- [] I have commented my code, particularly in hard-to-understand areas
- [] I have formatted and linted my code using python-black and pylint
- [] I have cleaned up unnecessary files
- [] My changes generate no new warnings
- [] My changes follow the existing code-style
- [] My changes are relevant to the project

# Any other information (e.g how to test the changes)

Without my changes, you can set headless to false and run the program. You will notice a timeout exception comfing from playwright without any indications to the user as to why it happened.
With my changes however, it performs a check to see if the reddit login is returning an error message, if it does it let's the user know to fix his credentials inside of config.toml.
pull/1615/head
xyba 2 years ago committed by GitHub
parent f2d89a10dd
commit eb7d1e9440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -116,6 +116,19 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
page.locator("button[class$='m-full-width']").click()
page.wait_for_timeout(5000)
login_error_div = page.locator(".AnimatedForm__errorMessage").first
if login_error_div.is_visible():
login_error_message = login_error_div.inner_text()
if login_error_message.strip() == "":
# The div element is empty, no error
pass
else:
# The div contains an error message
print_substep("Your reddit credentials are incorrect! Please modify them accordingly in the config.toml file.", style="red")
exit()
else:
pass
page.wait_for_load_state()
# Get the thread screenshot
page.goto(reddit_object["thread_url"], timeout=0)

Loading…
Cancel
Save