Update wrapper.py

This commit is contained in:
akamhy 2020-05-04 09:01:33 +05:30 committed by GitHub
parent 53561ec9c4
commit 9ab503f4ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,14 +20,17 @@ class ArchivingNotAllowed(Exception):
class PageNotSavedError(Exception): class PageNotSavedError(Exception):
""" """
Files like robots.txt are set to deny robot archiving. When unable to save a webpage.
Wayback machine respects these file, will not archive. """
class ArchiveNotFound(Exception):
"""
When a page was never archived but client asks for old archive.
""" """
class InvalidUrlError(Exception): class InvalidUrlError(Exception):
""" """
Files like robots.txt are set to deny robot archiving. Raised when url doesn't follow the standard url format.
Wayback machine respects these file, will not archive.
""" """
def clean_url(url): def clean_url(url):
@ -73,7 +76,7 @@ def near(
import json import json
data = json.loads(response.read().decode(encoding)) data = json.loads(response.read().decode(encoding))
if not data["archived_snapshots"]: if not data["archived_snapshots"]:
raise PageNotSavedError("'%s' was not archived." % url) raise ArchiveNotFound("'%s' is not yet archived." % url)
archive_url = (data["archived_snapshots"]["closest"]["url"]) archive_url = (data["archived_snapshots"]["closest"]["url"])
return archive_url return archive_url