Created
November 23, 2011 00:24
-
-
Save willf/1387532 to your computer and use it in GitHub Desktop.
Track tweets on some topic
This file contains hidden or 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 'date' | |
TweetStream.configure do |config| | |
config.consumer_key = '<your key>' | |
config.consumer_secret = '<your secret>' | |
config.oauth_token = '<your token>' | |
config.oauth_token_secret = '<your token secret>' | |
config.auth_method = :oauth | |
config.parser = :json_gem | |
end | |
# Change the words you want to track | |
TweetStream::Client.new.track('football', 'baseball', 'soccer', 'cricket') do |status| | |
begin | |
# The Tweet id | |
id = status.id | |
# The text of the tweet, with new lines (returns) replaced by spaces | |
txt = status.text.gsub(/\n/," ") | |
# The date of the tweet, printed out in a slightly more useful form for | |
# our purposes | |
d = DateTime.parse(status.created_at).strftime("%Y-%m-%d\t%H:%M:%S") | |
puts [id,txt,d].join("\t") | |
rescue Exception => e | |
puts "!!! Error: #{e.to_s}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment