From 7312ed1f4f89d8bbceb206dd86e79db5e5251713 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Sun, 24 Jan 2021 16:53:36 +0530 Subject: [PATCH] set cached_save to True if archive older than 3 mins. --- waybackpy/wrapper.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index bea9a7a..feef542 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -159,7 +159,18 @@ class Url: latest_version=self.latest_version, instance=self, ) - self.timestamp = datetime.utcnow() + + m = re.search(r"https?://web.archive.org/web/([0-9]{14})/http", archive_url) + str_ts = m.group(1) + ts = datetime.strptime(str_ts, "%Y%m%d%H%M%S") + now = datetime.utcnow() + total_seconds = int((now - ts).total_seconds()) + + if total_seconds > 60 * 3: + self.cached_save = True + + self.timestamp = ts + return self def get(self, url="", user_agent="", encoding=""):