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>
This commit is contained in:
parent
be7642c837
commit
1ea9548d46
@ -108,11 +108,24 @@ class Url:
|
|||||||
encoding = "UTF-8"
|
encoding = "UTF-8"
|
||||||
return response.read().decode(encoding.replace("text/html", "UTF-8", 1))
|
return response.read().decode(encoding.replace("text/html", "UTF-8", 1))
|
||||||
|
|
||||||
def near(self, year=None, month=None, day=None, hour=None, minute=None):
|
def get_response(self, req):
|
||||||
"""Return the closest Wayback Machine archive to the time supplied.
|
"""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.
|
Supported params are year, month, day, hour and minute.
|
||||||
Any non-supplied parameters default to the current time.
|
The non supplied parameters are default to the runtime time.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
now = datetime.utcnow().timetuple()
|
now = datetime.utcnow().timetuple()
|
||||||
timestamp = _wayback_timestamp(
|
timestamp = _wayback_timestamp(
|
||||||
|
Loading…
Reference in New Issue
Block a user