Skip to content
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

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -76,6 +77,15 @@ def bingSearches(self, numberOfSearches: int, pointsCounter: int = 0):
pointsCounter = points
else:
break

if points <= pointsCounter:
Copy link

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.

attempt += 1
if attempt == 2:
logging.warning(
Copy link

Choose a reason for hiding this comment

The 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 points and pointsCounter, or even the search term that led to this situation. This additional information can be invaluable during troubleshooting.

"[BING] Possible blockage. Refreshing the page."
)
self.webdriver.refresh()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Using self.webdriver.refresh() to attempt to resolve a blockage is a straightforward approach. However, consider the implications of this action on the state of the web driver and the current session. For instance, refreshing might reset any transient state or cookies that are essential for the search operation. It might be worth exploring alternative strategies, such as navigating to a different page or restarting the search session entirely.

attempt = 0
Comment on lines 77 to +88
Copy link

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Resetting the attempt counter to 0 after a page refresh is a clear and understandable action. However, this logic is tightly coupled with the loop's structure and the specific condition being checked. Consider encapsulating this retry logic into a separate method or using a more generic retry mechanism. This could improve code readability and make the retry logic reusable across different parts of the application.

logging.info(
f"[BING] Finished {self.browser.browserType.capitalize()} Edge Bing searches !"
)
Expand Down
Loading