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

Add reverse to snapshots() #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Add reverse to snapshots()
Add the option to get snapshots in reverse (from newest to oldest). This is especially useful since the snapshots() method returns a generator!
  • Loading branch information
jjmaestro authored Feb 26, 2024
commit c1a39a367936313c6d2ea674ffabc8e6d488b768
5 changes: 4 additions & 1 deletion waybackpy/cdx_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def oldest(self) -> CDXSnapshot:
"""
return self.near(year=1994, month=1, day=1)

def snapshots(self) -> Generator[CDXSnapshot, None, None]:
def snapshots(self, reverse: bool = False) -> Generator[CDXSnapshot, None, None]:
"""
This function yields the CDX data lines as snapshots.

Expand Down Expand Up @@ -373,6 +373,9 @@ def snapshots(self) -> Generator[CDXSnapshot, None, None]:
# at once, thus there should be no issues of too much memory usage.
snapshot_list = entry.split("\n")

if reverse:
snapshot_list.reverse()

for snapshot in snapshot_list:

# 14 + 32 == 46 ( timestamp + digest ), ignore the invalid entries.
Expand Down