Skip to content

Instantly share code, notes, and snippets.

@kanna5
Created April 9, 2021 00:31
Show Gist options
  • Save kanna5/e23c177ae631633f02b46326b1d51d8b to your computer and use it in GitHub Desktop.
Save kanna5/e23c177ae631633f02b46326b1d51d8b to your computer and use it in GitHub Desktop.
Get the most recent snapshot of <URL> from the Wayback Machine
#!/bin/bash
# Get the most recent snapshot of <URL> from the Wayback Machine
usage() {
echo "Usage: $0 [-o] <URL>" 1>&2
exit 1
}
open=0
url=
while [[ "$#" -gt 0 ]]; do
case "$1" in
-o|--open)
open=1 ;;
*)
[[ -n "$url" ]] && usage
url=$1 ;;
esac
shift
done
if [[ -z "$url" ]]; then
usage
fi
archived=$(curl -sSG --data-urlencode "url=$url" http://archive.org/wayback/available | jq -r .archived_snapshots.closest.url | sed 's/^http:/https:/')
[[ "$archived" == "null" ]] && exit 1
echo "$archived"
[[ "$open" -eq 1 ]] && xdg-open "$archived"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment