Sunday, March 1, 2009

Sunday hax0ring with Twitter

I was getting a little tired of just changing my userpic on Twitter automagically every couple of hours, so decided to make one of my pics a composite image of all my 'friends' there - staring back at them as it were. It turns out it's pretty easy to do with a shell script and their open api.

#!/bin/bash
echo "getting friends list:"
curl http://twitter.com/statuses/friends/cnawan.xml > cnawans-friendlist.xml

echo "trimming friends list:"
grep "/profile_image_url" cnawans-friendlist.xml >
cnawans-friends-pictures.txt
echo "more trimming"
sed -i 's/<profile_image_url>//g' cnawans-friends-pictures.txt
echo "yet more trimming:"
sed -i 's/<\/profile_image_url>//g' cnawans-friends-pictures.txt

echo "getting friends pictures:"
wget --input-file=cnawans-friends-pictures.txt

echo "averaging pictures:"
convert -average *.jpg cnawans-friends-pictures-averaged.jpg

..and set it as my userpic with a cron job like the others:

curl --header "Expect:" -F
'image=@/home/../cnawans-friends-pictures-averaged.jpg' -u
USERNAME:PASSWORD http://twitter.com/account/update_profile_image.xml


As it stands, it only uses the jpgs, not the few pngs that are on the list. I might adapt the script to do them all, but the jpgs tend to be photos more often and make the averaged image look more like a spooky face. :)

No comments: