Skip to content

Instantly share code, notes, and snippets.

@Brandon-Rozek
Created December 24, 2022 17:21
Show Gist options
  • Save Brandon-Rozek/bc850da353a3531e91348068035475fb to your computer and use it in GitHub Desktop.
Save Brandon-Rozek/bc850da353a3531e91348068035475fb to your computer and use it in GitHub Desktop.
Script that takes a URL and requests the Internet Archive to snapshot it.
#!/bin/env python
from argparse import ArgumentParser
from urllib import request
from urllib.parse import urlparse
import sys
parser = ArgumentParser(description="Request Internet Archive to save the site")
parser.add_argument("URL", type=str, help="URL to save")
parser.add_argument("-s", action='store_true', help="Silent. Makes output less verbose")
args = vars(parser.parse_args())
INPUT_URL = args['URL']
SILENT = args.get('s')
# Remove scheme from URL
parsed_url = urlparse(INPUT_URL)
scheme = f"{parsed_url.scheme}://"
save_url = parsed_url.geturl().replace(scheme, "", 1)
try:
if not SILENT:
print("Sending request to the internet archive...")
response = request.urlopen(f"https://web.archive.org/save/{save_url}")
if not SILENT:
print("Archive Link:", response.url)
else:
print(response.url)
except Exception as e:
print(e)
print("Failed to save to the Internet Archive")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment