-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update searches.py to refresh when blocked #87
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ def bingSearches(self, numberOfSearches: int, pointsCounter: int = 0): | |
self.webdriver.get("https://bing.com") | ||
|
||
i = 0 | ||
attempt = 0 | ||
for word in search_terms: | ||
i += 1 | ||
logging.info(f"[BING] {i}/{numberOfSearches}") | ||
|
@@ -76,6 +77,15 @@ def bingSearches(self, numberOfSearches: int, pointsCounter: int = 0): | |
pointsCounter = points | ||
else: | ||
break | ||
|
||
if points <= pointsCounter: | ||
attempt += 1 | ||
if attempt == 2: | ||
logging.warning( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Logging a warning when a possible blockage is detected is a good practice for monitoring and debugging. However, consider enhancing the log message with more context, such as the current value of |
||
"[BING] Possible blockage. Refreshing the page." | ||
) | ||
self.webdriver.refresh() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Using |
||
attempt = 0 | ||
Comment on lines
77
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Introducing a retry mechanism based on the number of attempts is a good resilience strategy. However, resetting the attempt counter to 0 after refreshing the page might not always be the best approach. Consider scenarios where the page refresh does not resolve the issue, leading to a potential infinite loop if the condition triggering the refresh persists. It might be beneficial to implement a maximum attempt limit or a more sophisticated back-off strategy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Resetting the |
||
logging.info( | ||
f"[BING] Finished {self.browser.browserType.capitalize()} Edge Bing searches !" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (code_clarification): The condition
if points <= pointsCounter
for triggering a page refresh seems to rely on the assumption that points should always increase after each search. While this might be true in most cases, it's important to verify this assumption against the application's behavior or external dependencies like the Bing search engine. If there are legitimate scenarios where points might not increase (e.g., rate limiting, daily caps), this could lead to unnecessary page refreshes.