Update wrapper.py
This commit is contained in:
parent
e66c70c8ee
commit
52b4bb9ac7
@ -26,7 +26,8 @@ class PageNotSavedError(Exception):
|
|||||||
|
|
||||||
class InvalidUrlError(Exception):
|
class InvalidUrlError(Exception):
|
||||||
"""
|
"""
|
||||||
When the inpute url doesn't have '.' in it.
|
Files like robots.txt are set to deny robot archiving.
|
||||||
|
Wayback machine respects these file, will not archive.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def save(url,UA=default_UA):
|
def save(url,UA=default_UA):
|
||||||
@ -68,15 +69,14 @@ def near(
|
|||||||
encoding = response.info().get_content_charset('utf8')
|
encoding = response.info().get_content_charset('utf8')
|
||||||
import json
|
import json
|
||||||
data = json.loads(response.read().decode(encoding))
|
data = json.loads(response.read().decode(encoding))
|
||||||
print(data)
|
|
||||||
if not data["archived_snapshots"]:
|
if not data["archived_snapshots"]:
|
||||||
raise PageNotSavedError("'%s' was not archived." % url)
|
raise PageNotSavedError("'%s' was not archived." % url)
|
||||||
|
|
||||||
archive_url = (data["archived_snapshots"]["closest"]["url"])
|
archive_url = (data["archived_snapshots"]["closest"]["url"])
|
||||||
return archive_url
|
return archive_url
|
||||||
|
|
||||||
def oldest(url,UA=default_UA):
|
def oldest(url,UA=default_UA,year=1994):
|
||||||
return near(url,year=1995,UA=UA)
|
return near(url,year=year,UA=UA)
|
||||||
|
|
||||||
def newest(url,UA=default_UA):
|
def newest(url,UA=default_UA):
|
||||||
return near(url,UA=UA)
|
return near(url,UA=UA)
|
||||||
|
Loading…
Reference in New Issue
Block a user