-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Substituted _internetarchive_ Internet Archive API for _wayback_ Wayback Machine API. Online upload process now solid and reliable - Bookmark loop full log option - Logs styled - Log levels implemented - CLI
- Loading branch information
1 parent
5906832
commit adb7dcd
Showing
14 changed files
with
215 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
""" | ||
.. include:: ./documentation.md | ||
""" | ||
|
||
from anchorage.anchor_infrs.infrastructure import init | ||
from anchorage.bookmarks import bookmarks, path, load | ||
from anchorage.anchor import anchor_locally, anchor_online | ||
from anchorage.anchor_tools.local import add as add_local, server | ||
from anchorage.anchor_tools.online import add as add_online |
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 |
---|---|---|
@@ -1,38 +1,51 @@ | ||
from internetarchive import get_item | ||
from wayback import WaybackClient | ||
from archivenow import archivenow | ||
|
||
from Alexandria.general.console import print_color | ||
from alexandria.shell import print_color, suppress_stdout | ||
from alexandria.shell.color import colors | ||
|
||
from anchorage.anchor_utils.shell import shell | ||
from anchorage.anchor_utils.aesthetic import str_log_info, str_log_error, str_log_success | ||
|
||
|
||
def add(url, archives=None, overwrite=False): | ||
def add(url, archive='ia', api_key=None, overwrite=False): | ||
""" | ||
Archive a website in one of the four archives supported by Archive Now (archivenow). | ||
TODO: Recognize internetarchive upload error messages as failures. | ||
:param url: URL of website to be archived. | ||
:param archives: List or string of flags specifying in which archives to save the website. | ||
Available flags: | ||
- https://pypi.org/project/archivenow/ | ||
Example: | ||
"all" | ||
"--ia --is" | ||
["--ia", "--is"] | ||
:param archive: List or string specifying archives to which to save the website. | ||
Available archives: | ||
- 'all': All archives | ||
- 'ia': Internet Archive (default) | ||
- 'is': Archive.is | ||
- 'mg': Megalodon.jp | ||
- 'cc': Perma.cc | ||
:param api_key: Perma.cc API key. Format: | ||
{"cc_api_key":"$YOUR-Perma-cc-API-KEY"} | ||
:param overwrite: Archive URL even if it's already present in the Internet Archive. | ||
""" | ||
|
||
def upload(url): | ||
flags = ' '.join(archives) if archives is list else archives if not isinstance(archives, type(None)) else "" | ||
try: | ||
copy = shell(f"archivenow {flags} {url}") | ||
return copy.stdout, copy.stderr | ||
except: | ||
print("Error archiving: ", end="") | ||
print_color(url, "red") | ||
if archive == 'cc': | ||
with suppress_stdout(): | ||
archive_url = archivenow.push(url, archive, api_key)[0] | ||
else: | ||
with suppress_stdout(): | ||
archive_url = archivenow.push(url, archive)[0] | ||
log = str_log_success(url + " -> -> -> " + archive_url) | ||
return log | ||
except BaseException as e: | ||
print(str_log_error(url)) | ||
print_color(e, "red") | ||
|
||
if get_item(url).exists: | ||
try: | ||
archive_latest = next(WaybackClient().search(url)) # Search for URL using the WaybackMachine API | ||
if overwrite: | ||
return upload(url) | ||
else: | ||
return "Bookmark already present in the Internet Archive" | ||
else: | ||
return str_log_info("SKIPPED", url + " => => => " + archive_latest[7]) | ||
except: | ||
# If bookmark search yields "0" error (defined by Python _wayback_) | ||
return upload(url) |
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
Oops, something went wrong.