Created
July 12, 2011 07:34
-
-
Save phobeo/1077559 to your computer and use it in GitHub Desktop.
stream campus tweets into mongodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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