From c1a39a367936313c6d2ea674ffabc8e6d488b768 Mon Sep 17 00:00:00 2001 From: Javier Maestro Date: Mon, 26 Feb 2024 00:15:12 +0000 Subject: [PATCH] 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! --- waybackpy/cdx_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/waybackpy/cdx_api.py b/waybackpy/cdx_api.py index 4bd8291..b89da38 100644 --- a/waybackpy/cdx_api.py +++ b/waybackpy/cdx_api.py @@ -336,7 +336,7 @@ class WaybackMachineCDXServerAPI: """ 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. @@ -373,6 +373,9 @@ class WaybackMachineCDXServerAPI: # 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.