Last active
December 21, 2015 14:39
-
-
Save noff/6321451 to your computer and use it in GitHub Desktop.
Daemon for track tweets by keywords
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
#!/usr/bin/env ruby | |
root = File.expand_path(File.dirname(__FILE__)) | |
root = File.dirname(root) until File.exists?(File.join(root, 'config')) | |
Dir.chdir(root) | |
require File.join(root, "config", "environment") | |
require 'tweetstream' | |
$running = true | |
Signal.trap('TERM') do | |
$running = false | |
quit | |
end | |
Rails.logger.auto_flushing = true | |
while($running) do | |
EM.run do | |
TweetStream.configure do |config| | |
config.consumer_key = '...' | |
config.consumer_secret = '...' | |
config.oauth_token = '...' | |
config.oauth_token_secret = '...' | |
config.auth_method = :oauth | |
end | |
client = TweetStream::Client.new | |
client.on_error do |message| | |
Rails.logger.error message | |
puts "ERROR: #{message.inspect}" | |
end | |
EM::PeriodicTimer.new(5) do | |
# ... some reconnections when needed | |
end | |
puts 'Run tracking' | |
client.track('#twijector', 'google') do |status, client| | |
puts status.text | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment