Created
July 19, 2012 22:12
-
-
Save tjluoma/3147226 to your computer and use it in GitHub Desktop.
Shell script which takes one argument (an URL) and attempts to add it to your Instapaper account using the official API
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
#!/bin/zsh | |
# add URL to instapaper | |
INSTAPAPER_USERNAME=you@example.com | |
# if you have one | |
INSTAPAPER_PASSWORD='seKret' | |
# | |
# You shouldn't need to edit anything below here | |
# | |
NAME="$0:t" | |
CACHE="$HOME/.$NAME" | |
ADD_URL=$@ | |
fgrep -q "$ADD_URL" "$CACHE" && echo "$NAME: $ADD_URL found in $CACHE (previously sent to Instapaper)" && exit 0 | |
URL_BASE="https://instapaper.com/api/add" | |
STATUS=$(curl -s "$URL_BASE" \ | |
-F username="$INSTAPAPER_USERNAME" \ | |
-F password="$INSTAPAPER_PASSWORD" \ | |
-F url="$ADD_URL") | |
case "$STATUS" in | |
200|201) | |
echo "$NAME: success $ADD_URL" | |
echo "$ADD_URL" >>| $CACHE | |
exit 0 | |
;; | |
*) | |
echo "$NAME: failed to add $ADD_URL to Instapaper account. Error code $STATUS (should be 200 or 201)" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment