Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Track tweets on some topic
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
# Change the words you want to track'football', 'baseball', 'soccer', 'cricket') do |status|
# The Tweet id
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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.