Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move from Memento to CDX search, bump to v0.3.0
Cf.: https://github.com/internetarchive/wayback/blob/master/wayback-cdx-server/README.md Thanks to @ErikBorra for flagging/suggesting.
- Loading branch information
Showing
12 changed files
with
99 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
import unittest | ||
import waybackpack | ||
import sys, os | ||
|
||
class Test(unittest.TestCase): | ||
def test_snapshot_index(self): | ||
url = "dol.gov" | ||
snapshots = waybackpack.search(url) | ||
assert(len(snapshots) > 0) | ||
assert(snapshots[0]["timestamp"] == "19961102145216") | ||
clipped = waybackpack.search( | ||
url, | ||
to_date="1996" | ||
) | ||
assert(len(clipped) < len(snapshots)) | ||
assert(len(clipped) == 4) | ||
|
||
def test_uniques(self): | ||
url = "dol.gov" | ||
uniques = waybackpack.search( | ||
url, | ||
to_date="1996", | ||
uniques_only=True | ||
) | ||
assert(len(uniques) == 2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .session import Session | ||
from .timemap import TimeMap | ||
from .asset import Asset | ||
from .pack import Pack | ||
__version__ = "0.2.0" | ||
from .cdx import search | ||
__version__ = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .session import Session | ||
|
||
SEARCH_URL = "https://web.archive.org/cdx/search/cdx" | ||
|
||
def search(url, | ||
from_date=None, | ||
to_date=None, | ||
uniques_only=False, | ||
collapse=None, | ||
session=None): | ||
|
||
session = session or Session() | ||
cdx = session.get(SEARCH_URL, params={ | ||
"url": url, | ||
"from": from_date, | ||
"to": to_date, | ||
"showDupeCount": "true", | ||
"output": "json", | ||
"collapse": collapse | ||
}).json() | ||
fields = cdx[0] | ||
if len(cdx) < 2: return [] | ||
snapshots = [ dict(zip(fields, row)) for row in cdx[1:] ] | ||
if uniques_only: | ||
return [ s for s in snapshots if int(s["dupecount"]) == 0 ] | ||
else: | ||
return snapshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.