Skip to content

Instantly share code, notes, and snippets.

@johnsto
Created November 1, 2014 11:38
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 johnsto/c7e2445e24c4d8e56053 to your computer and use it in GitHub Desktop.
Save johnsto/c7e2445e24c4d8e56053 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Prints the days remainig until Christmas onto an image and (optionally)
# sets it as the user's Twitter avatar.
avatar="avatar.png"
date="25 Dec"
user=
while getopts 'a:d:u:' flag; do
case "${flag}" in
a) avatar="${OPTARG}" ;;
d) date="${OPTARG}" ;;
u) user="${OPTARG}" ;;
*) error "Unknown argument ${flag}" ;;
esac
done
days="$(( $(date --date="$date" +%j) - $(date +%j) ))"
if [[ $days -lt 10 ]]; then
text="$days!"
else
text="$days"
fi
convert \
-gravity SouthWest \
-pointsize 72 \
-stroke "#000" -strokewidth 2 -fill "#fff" -draw "text 0,0 '$text'" \
$avatar tmp_$avatar
if [[ ! -z $user ]]; then
curl \ #-v --compressed \
-X POST \
-F "image=$(base64 -w0 tmp_$avatar)" \
-u $user \
"https://foauth.org/api.twitter.com/1.1/account/update_profile_image.json"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment