From cc3628ae18a155cfbf5e91d36a0871040f161298 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Sun, 16 Jan 2022 22:28:12 +0530 Subject: [PATCH] define __str__ for objects of WaybackMachineAvailabilityAPI class, the check for self.JSON ensures that the API was atleast called. --- waybackpy/availability_api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/waybackpy/availability_api.py b/waybackpy/availability_api.py index a132057..87844a9 100644 --- a/waybackpy/availability_api.py +++ b/waybackpy/availability_api.py @@ -31,10 +31,16 @@ class WaybackMachineAvailabilityAPI: self.headers = {"User-Agent": self.user_agent} self.payload = {"url": "{url}".format(url=self.url)} self.endpoint = "https://archive.org/wayback/available" + self.JSON = None def unix_timestamp_to_wayback_timestamp(self, unix_timestamp): return datetime.utcfromtimestamp(int(unix_timestamp)).strftime("%Y%m%d%H%M%S") + def __str__(self): + if not self.JSON: + return None + return self.archive_url + def json(self): self.request_url = full_url(self.endpoint, self.payload) self.response = requests.get(self.request_url, self.headers)