Flickrtweeter: automatically tweet your flickr pics
A few weeks ago I decided to roll my own script to automatically twitter an update if I posted a photo onto my flickr pages with a certain tag. I know that there are third party services out there that can do this for you (e.g. Snaptweet, Twittergram) but I thought it’d be an interesting project to do it myself. As well as (obviously) requiring flickr and twitter accounts, it also requires a bit.ly account and API key as it uses this service to produce a shortened URL for the photo to include in the tweet.
The script is written in Perl and is fairly straitforward. It pulls the Atom feed of my flickr account and checks any photos tagged “twitme” against a list of photos it has already seen and tweeted. It then passes the photo’s URL through bit.ly to get a shortened version and builds a tweet using a standard prefix, the photo’s title from flickr, and the bit.ly’ified URL. It then attempts to post the tweet.
The script uses LWP::Simple
for HTTP GET
s to flickr and bit.ly, XML::Simple
to parse the responses, Storable
to maintain a cache file of seen photos, Net::Twitter
to talk to twitter itself and URI::Escape
to escape the photo’s URL before passing it to bit.ly. It also uses the sysopen
call from Fcntl
to manage a lockfile - I run it as a cron job so this seemed a sensible precaution.
It can be configured by setting variables at the start of the script. All are commented (I hope) reasonably clearly. It can be downloaded and used under the terms of the GNU Public License. I originally called it flickr2twitter but as this appears to be the name of a Firefox Addon I have renamed it flickrtweeter.