Skip to content

Commit

Permalink
fix: Improve login error handling (develop)
Browse files Browse the repository at this point in the history
The login error handling was improved to exit when an error
is encountered, even if the error message is empty.  The
user agent string is now dynamically generated using the
browser version.

Signed-off-by: Jason Cameron <[email protected]>
  • Loading branch information
JasonLovesDoggo committed Jan 29, 2025
1 parent ccfb665 commit 4017f65
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions video_creation/screenshot_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
color_scheme="dark",
viewport=ViewportSize(width=W, height=H),
device_scale_factor=dsf,
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
user_agent=f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{browser.version}.0.0.0 Safari/537.36",
extra_http_headers={
"Dnt": "1",
"Sec-Ch-Ua": '"Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132"',
Expand All @@ -110,17 +110,12 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):

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()

print_substep(
"Your reddit credentials are incorrect! Please modify them accordingly in the config.toml file.",
style="red",
)
exit()
else:
pass

Expand Down

0 comments on commit 4017f65

Please sign in to comment.