From eb7d1e944038601b968a7d26fd072aac94c3d447 Mon Sep 17 00:00:00 2001 From: xyba <62798507+xyba1337@users.noreply.github.com> Date: Wed, 3 May 2023 22:56:28 +0200 Subject: [PATCH] Reddit credentials validation in screenshot_downloader.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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. --- video_creation/screenshot_downloader.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 1c3ab5e..48ed8be 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -115,6 +115,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