Skip to content

Instantly share code, notes, and snippets.

@phobeo
Created July 12, 2011 07:34
Show Gist options
  • Save phobeo/1077559 to your computer and use it in GitHub Desktop.
Save phobeo/1077559 to your computer and use it in GitHub Desktop.
stream campus tweets into mongodb
require 'rubygems'
require 'tweetstream'
require 'mongo'
CAMPUS_BBOX='39.447025911738,-0.35662933148245,39.470136313596,-0.33659356733534'
puts "Opening Mongo connection..."
conn = Mongo::Connection.new
db = conn.db("testdb")
tweets = db.collection("campus_tweets")
puts "listening for tweets..."
TweetStream::Client.new('espresso_test', 'espressions').on_error do |message|
puts "Oops! ERROR: #{message}"
end.filter.locations(CAMPUS_BBOX) { |status|
puts "[#{status.user.screen_name}] #{status.text}"
tweets.insert(status)
}
puts "all is well that ends well..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment