Skip to content

Instantly share code, notes, and snippets.

@arfon
Created January 21, 2012 12:54
Show Gist options
  • Save arfon/1652703 to your computer and use it in GitHub Desktop.
Save arfon/1652703 to your computer and use it in GitHub Desktop.
Tweet parsing with EventMachine
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
table.load_schema
TweetStream.configure do |config|
config.consumer_key = 'consumer_key'
config.consumer_secret = 'consumer_secret'
config.oauth_token = 'oauth_token'
config.oauth_token_secret = 'oauth_token_secret'
config.auth_method = :oauth
config.parser = :json_pure
end
EM.threadpool_size = 50
EM.run{
client = TweetStream::Client.new
def write_to_dynamo(status)
EM.defer do
tweet_hash = {:user_id => status.user.id,
:created_at => status.created_at,
:id => status.id,
:screen_name => status.user.screen_name}
table.items.create(tweet_hash)
end
end
client.track("Romney", "Gingrich") do |status|
write_to_dynamo(status)
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment