From ffe0810b12216da6d1e2b73c06fa3cb82bdf17e9 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Sat, 16 Jan 2021 12:06:08 +0530 Subject: [PATCH] flag to check if the archive saved is 30 mins older or not --- waybackpy/utils.py | 29 +++++++++++++++-------------- waybackpy/wrapper.py | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/waybackpy/utils.py b/waybackpy/utils.py index ed122fb..8bfee70 100644 --- a/waybackpy/utils.py +++ b/waybackpy/utils.py @@ -22,28 +22,28 @@ def _unix_ts_to_wayback_ts(unix_ts): return datetime.utcfromtimestamp(int(unix_ts)).strftime("%Y%m%d%H%M%S") -def _add_payload(self, payload): - if self.start_timestamp: - payload["from"] = self.start_timestamp +def _add_payload(instance, payload): + if instance.start_timestamp: + payload["from"] = instance.start_timestamp - if self.end_timestamp: - payload["to"] = self.end_timestamp + if instance.end_timestamp: + payload["to"] = instance.end_timestamp - if self.gzip != True: + if instance.gzip != True: payload["gzip"] = "false" - if self.match_type: - payload["matchType"] = self.match_type + if instance.match_type: + payload["matchType"] = instance.match_type - if self.filters and len(self.filters) > 0: - for i, f in enumerate(self.filters): + if instance.filters and len(instance.filters) > 0: + for i, f in enumerate(instance.filters): payload["filter" + str(i)] = f - if self.collapses and len(self.collapses) > 0: - for i, f in enumerate(self.collapses): + if instance.collapses and len(instance.collapses) > 0: + for i, f in enumerate(instance.collapses): payload["collapse" + str(i)] = f - payload["url"] = self.url + payload["url"] = instance.url def _ts(timestamp, data): @@ -220,7 +220,7 @@ def _archive_url_parser(header, url, latest_version=__version__, instance=None): WaybackError with an error message. """ - if "save redirected" in header: + if "save redirected" in header and instance: time.sleep(60) # makeup for archive time now = datetime.utcnow().timetuple() @@ -279,6 +279,7 @@ def _archive_url_parser(header, url, latest_version=__version__, instance=None): archive_url = newest_archive.archive_url m = re.search(r"web\.archive\.org/web/[0-9]{14}/.*", archive_url) if m: + instance.cached_save = True return m.group(0) if __version__ == latest_version: diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 8e13d09..067a75c 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -23,6 +23,7 @@ class Url: self.timestamp = None self._JSON = None self.latest_version = None + self.cached_save = False def __repr__(self): return "waybackpy.Url(url={url}, user_agent={user_agent})".format(