FlickrPress

Friday, October 16th, 2009

I wanted to be able to take photos from Flickr and post them to a WordPress blog automatically.

FlickrPress Workflow

Enter FlickrPress.

Downloads

Initial Release: 0.01
FlickrPress on GitHub

Installation and Configuration

Requirements

  • Any kind of Unix-y system that’s capable of running Perl
  • Some kind of way to periodically run applications (like cron)
  • A Flickr account (or accounts)
  • An account on a WordPress blog

Installation

You’ll need to have XML::RSS and WordPress::Post installed to use this tool.

FlickrPress is packaged as a standard Perl module, so you can install it just like you would any other:

perl Build.PL
./Build
./Build test
sudo ./Build install

If you don’t have root on your server, (for example, if you’re trying to run this on a shared host, like I do) I recommend checking out the awesome local::lib.
Once you follow their ‘bootstrapping config’ and set up your bashrc, it makes things feel like you’re on your own server. Just ‘cpan -i WordPress::Post’ or ‘./Build install’, and it just works!

So a full install using local::lib would look like:
Download and unpack local::lib and FlickrPress. In the local::lib directory:

perl Makefile.PL --bootstrap
make test && make install
echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc
. ~/.bashrc
cpan -i WordPress::Post
cpan -i XML::RSS #only if it's not already installed
cd ../FlickrPress-0.01
perl Build.PL
./Build test
./Build install

One caveat if you’re using local::lib and trying to run this tool from cron, is that you’ll probably want to use a wrapper script to correctly set up the environment.

Here’s mine, set up to work on my MediaTemple (gs) account and work with my local::lib setup:

#!/bin/bash

#set up environment
HOME=/home/68601/users/.home
eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)

# run the script
$HOME/perl5/bin/flickrpress.pl

Configuration

You need to edit the file “.flickrpress.conf” in your home directory. Contents should be YAML and provide all the following values:

 ---
 flickr:
    rss_uri: 'http://api.flickr.com/services/feeds/photos_public.gne?tags=mytag&lang=en-us&format=rss_200'
    authors:
        - myuser
        - anotheruser
 wordpress:
    xmlrpc_uri: "http://myblog.com/xmlrpc.php"
    username: "myuser"
    password: "mypass"

The RSS URI is the one that we poll from Flickr. This app has only been tested using feeds resulting from searching for a tag. (Edit the sample rss_uri above and put that tag you’re interested in in place of ‘mytag’.)

The ‘authors’ list allows you to specify a list of authors (flickr accounts) of images you will allow through to your blog using that tag. You can allow as many as you like — I have it configured so my wife and I can both post.

Also, you need to configure the script to run automatically. The Flickr RSS feed only returns 20 or so items, so you must run the script at least often enough so that it ‘sees’ each entry. I like to run mine every 30 minutes — keeps the load on the servers low, and it’s fast enough.