Searching Twitter with Ruby

After seeing this a few days ago, I thought it’d be fun and easy to whip up a little script that would dump tweets from around my area. Unfortunately, it was neither. I won’t bore you with my troubles, suffice it to say GitHub has now been added to my list of gem repositories.

I haven’t gone through much of the actual api yet, but so far it looks great. I did play around with a few different wrappers before finally getting down to business with twitter_search, which is nice, and thin, and jived nicely with my goal.

So here’s the code to fetch the last 15 tweets from ( thanks geocoder! ) my area. Simple, eh?

require 'rubygems'
require 'twitter_search'

tweets = TwitterSearch::Client.new.query :geocode => "28.599630,-81.289176,2mi"

tweets.each do |t|
  puts "@#{t.from_user} - #{t.text}n"
end

The next step is to figure out how to look up geocodes automatically, and maybe build some sort of web interface. But not tonight.