Add a variable to fetch the latest snapshot only#10
Open
vladkvit wants to merge 2 commits into
Open
Conversation
The latest snapshot within the provided time range.
shanept
suggested changes
Feb 17, 2024
shanept
left a comment
There was a problem hiding this comment.
Line 197 throws an error if filtered_snapshots is an empty array:
2024-02-17 22:29:46 [scrapy.core.scraper] ERROR: Error downloading <GET https://web.archive.org/cdx/search/cdx?url=https%3A//kcg.wikipedia.org/&output=json&fl=timestamp,original,statuscode,digest>
Traceback (most recent call last):
File "/home/shane/.local/lib/python3.8/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
result = context.run(gen.send, result)
File "/home/shane/.local/lib/python3.8/site-packages/scrapy/core/downloader/middleware.py", line 68, in process_response
method(request=request, response=response, spider=spider)
File "/home/shane/.local/lib/python3.8/site-packages/scrapy_wayback_machine/__init__.py", line 77, in process_response
snapshot_requests = self.build_snapshot_requests(response, meta)
File "/home/shane/.local/lib/python3.8/site-packages/scrapy_wayback_machine/__init__.py", line 134, in build_snapshot_requests
for snapshot in self.filter_snapshots(snapshots):
File "/home/shane/.local/lib/python3.8/site-packages/scrapy_wayback_machine/__init__.py", line 197, in filter_snapshots
return [filtered_snapshots[-1]]
IndexError: list index out of range
Suggest modifying slightly. The following works well for me:
if self.fetch_latest_only and len(filtered_snapshots):
return [filtered_snapshots[-1]]
else:
return filtered_snapshotsLine 197 threw an error if filtered_snapshots is an empty array:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Returns only the latest snapshot within the provided time range.