-
-
Notifications
You must be signed in to change notification settings - Fork 36
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 wikipedia_scratcher.py #93
Conversation
Avoiding Duplicate Requests: In the get_response_elems function, its making two separate requests to the same URL. Instead, you can reuse the response object obtained in the with block. This reduces redundant HTTP requests and improves efficiency.
Checking it! |
@siddheshhr please update the description: fix the issue link (#93 is this PR) and complete the appropriate check boxes |
Have made the changes,if any more corrections let me know |
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.
thank you for this work! please see requested changes
wikipedia/wikipedia_scratcher.py
Outdated
except requests.HTTPError as e: | ||
print(f"HTTP Error: {e}", file=sys.stderr) | ||
return {} | ||
except requests.RequestException as e: | ||
print(f"Request Exception: {e}", file=sys.stderr) | ||
return {} | ||
except KeyError as e: | ||
print(f"KeyError: {e}. Search data is: {search_data}", file=sys.stderr) | ||
return {} |
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.
i don't think these errors should result in continued operation. the original code resulted in either a script exit or a raised exception
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.
made the below change
except requests.HTTPError as e:
print(f"HTTP Error: {e}", file=sys.stderr)
raise
except requests.RequestException as e:
print(f"Request Exception: {e}", file=sys.stderr)
raise
except KeyError as e:
print(f"KeyError: {e}. Search data is: {search_data}", file=sys.stderr)
raise
Instead of printing messages and continuing execution, errors are raised using raise. @TimidRobot please check it once
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.
thank you
Avoiding Duplicate Requests: In the get_response_elems function, its making two separate requests to the same URL. Instead, you can reuse the response object obtained in the with block. This reduces redundant HTTP requests and improves efficiency.
Fixes
Optimizes get_response_elems by reusing a single request for the URL, avoiding duplicates.
Description
In the get_response_elems function, its making two separate requests to the same URL. Instead, you can reuse the response object obtained in the with block. This reduces redundant HTTP requests and improves efficiency.
Checklist
Update index.md
).main
ormaster
).visible errors.
Developer Certificate of Origin
For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."
Developer Certificate of Origin