Update wrapper.py

This commit is contained in:
akamhy 2020-05-05 09:57:39 +05:30 committed by GitHub
parent 057c61d677
commit 7d434c3f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@ def get(url,encoding=None,UA=default_UA):
if encoding is None: if encoding is None:
try: try:
encoding= resp.headers['content-type'].split('charset=')[-1] encoding= resp.headers['content-type'].split('charset=')[-1]
except: except AttributeError:
encoding = "UTF-8" encoding = "UTF-8"
return resp.read().decode(encoding) return resp.read().decode(encoding)
@ -72,7 +72,7 @@ def near(
timestamp = wayback_timestamp(year,month,day,hour,minute) timestamp = wayback_timestamp(year,month,day,hour,minute)
request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % (clean_url(url), str(timestamp)) request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % (clean_url(url), str(timestamp))
hdr = { 'User-Agent' : '%s' % UA } hdr = { 'User-Agent' : '%s' % UA }
req = Request(request_url, headers=hdr) req = Request(request_url, headers=hdr) # nosec
response = urlopen(req) #nosec response = urlopen(req) #nosec
data = json.loads(response.read().decode("UTF-8")) data = json.loads(response.read().decode("UTF-8"))
if not data["archived_snapshots"]: if not data["archived_snapshots"]: