Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Created July 19, 2012 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjluoma/3147226 to your computer and use it in GitHub Desktop.
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
#!/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