Skip to content

Add a variable to fetch the latest snapshot only #10

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vladkvit
Copy link

Returns only the latest snapshot within the provided time range.

The latest snapshot within the provided time range.
Copy link

@shanept shanept left a comment

Choose a reason for hiding this comment

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

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_snapshots

Line 197 threw an error if filtered_snapshots is an empty array:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants