Created
April 9, 2021 00:31
-
-
Save kanna5/e23c177ae631633f02b46326b1d51d8b to your computer and use it in GitHub Desktop.
Get the most recent snapshot of <URL> from the Wayback Machine
This file contains hidden or 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
#!/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