This is how I gather my twitterings into the blog. I just scrape the rss feed. The twitter api may allow for something more sophisticated but this Just Works.
It's just too easy in ruby/rails:
1 class TwitterHandler
2 def update( strFile)
3 require 'open-uri'
4 require 'simple-rss'
5
6 oRss = SimpleRSS.parse( open( strFile))
7
8 oRss.items.each do |oItem|
9 strBody = oItem.description
10 strBody.gsub!( /^petersblog: /, '')
11 strTitle = "Twittering: #{oItem.pubDate.strftime( "%d %B %Y %H:%M")}"
12
13 if not Post.find_by_title( strTitle)
14 oPost = Post.new( :title => strTitle, :body => strBody, :created => oItem.pubDate)
15 oPost.Taglist = "twittering"
16 end
17 end
18 end
19 end
20
21 The above is only wrapped in a class because that is how the first rspec example I read was laid out.
22
23 Then there is a rake task to run the above:
24
25 <ruby>
26 task (:twitter => :environment) do
27 require 'lib/TwitterHandler'
28
29 oTwitter = TwitterHandler.new
30 oTwitter.update( "http://twitter.com/statuses/user_timeline/16738335.rss")
31 end
Toggle Line Numbers
Then a cron job:
13,28,43,58 * * * * bash -c "cd /var/www/PetersBlogger/current; rake -s RAILS_ENV=production twitter"
This polls every 15 minutes. The '-s' stops rake outputting a needless 'In directory blah' message which cron dutifully emails to me.
I'm enjoying using twitter, I like the medium, short and pithy. Not really suitable for code snippets though.