Thursday, September 10, 2009

Customized tweeting of RSS feed's with feed-aggregation-tools

There are many web applications that offer different takes on what a "power user" does with Twitter. For example feedtweet takes an RSS feed and tweets the latest entries. But what if you want to tweet the feed entries in a manner other than feedtweet's designers thought you should do? What if you do not want to hand your twitter account credentials to a third party? What if you want to have control over your own ship? Blessedly it's relatively simple to write tools for both RSS feed consumption and tweeting.

My own open source project, Feed Aggregation Tools, is one such home grown toolset. It doesn't come packaged as a slick website, instead it's a pile of Java and Groovy code you download and run from a cron job preferably on a Unix-like server (Solaris, Linux, FreeBSD, etc).

A number of tools are built into the Feed Aggregation Tools and its twitter capabilities are a minor bit of what it can do. In any case let's look at how to do interesting things with RSS feeds and Twitter.

First step is installation and setup. This will require having Java, Groovy, Ant and Mercurial installed on your system. Once those are set up follow the instructions (basically run "ant setup").

Among the tools are ones to retrieve an RSS or Atom feed including keeping a long archive of posts on a given feed. For example causes a given RSS feed to be saved in the file "rss-example-local.xml" and further it remembers old entries that were in the RSS feed even when the RSS feed no longer contains those entries.

groovy scripts/feedarchive.groovy <a href="http://example.com/rss.xml" title="http://example.com/rss.xml">http://example.com/rss.xml</a> rss-example-local.xml

But, we are here to talk about twitter. The first tool is tweet which is a simple wrapper around twitter.com's JSON interface.

groovy scripts/tweet.groovy tweetID <a href="http://example.com/url-to-tweet" title="http://example.com/url-to-tweet">http://example.com/url-to-tweet</a> "message to tweet"

This sends a tweet listing both the URL and the message to the account credentials given in "tweetID". The account credentials are given as "account:password".

The next tool, feedtweet, does a combination of the feedarchive script mentioned above along with tweeting new entries. For every new feed entry (not in the feed archive) it tweets the entry.

groovy scripts/feedtweet.groovy <a href="http://example.com/rss.xml" title="http://example.com/rss.xml">http://example.com/rss.xml</a> tweeted.xml 100  "account:password"
</codde>
 
The last tool that's been written, <a href="http://hg.davidherron.com/index.cgi/feed-aggregation-tools/file/tip/scripts/feedrandtweet.groovy#l1">feedrandtweet</a>, tweets a random entry from a feed.  It doesn't save the feed locally, it simply reads the existing feed and tweets a randomly chosen entry.
 
<code>
groovy scripts/feedrandtweet.groovy <a href="http://example.com/rss.xml
">http://example.com/rss.xml
</a>