From 1ea9548d463b46f4671b0fe2052bac75e5e51886 Mon Sep 17 00:00:00 2001 From: AntiCompositeNumber Date: Wed, 22 Jul 2020 01:21:44 -0400 Subject: [PATCH] Raise WaybackError from URLError and include URL (#19) * Raise WaybackError from URLError and include URL * python2 compatibility Co-authored-by: Akash <64683866+akamhy@users.noreply.github.com> --- waybackpy/wrapper.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 8c2447e..17143b6 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -108,11 +108,24 @@ class Url: encoding = "UTF-8" return response.read().decode(encoding.replace("text/html", "UTF-8", 1)) - def near(self, year=None, month=None, day=None, hour=None, minute=None): - """Return the closest Wayback Machine archive to the time supplied. + def get_response(self, req): + """Get response for the supplied request.""" + try: + response = urlopen(req) #nosec + except Exception: + try: + response = urlopen(req) #nosec + except Exception as e: + exc = WaybackError("Error while retrieving %s" % req.full_url) + exc.__cause__ = e + raise exc + return response + + def near(self, **kwargs): + """ Returns the archived from Wayback Machine for an URL closest to the time supplied. + Supported params are year, month, day, hour and minute. + The non supplied parameters are default to the runtime time. - Supported params are year, month, day, hour and minute. - Any non-supplied parameters default to the current time. """ now = datetime.utcnow().timetuple() timestamp = _wayback_timestamp(