Skip to content

Instantly share code, notes, and snippets.

@nojima
Created February 16, 2014 11:48
Show Gist options
  • Save nojima/9032975 to your computer and use it in GitHub Desktop.
Save nojima/9032975 to your computer and use it in GitHub Desktop.
description "Twitter Timeline Logger"
author "Yusuke Nojima"
start on runlevel[2345]
stop on runlevel[016]
chdir /opt/timeline-logger
exec bin/timeline-logger --config etc/config.yml >> /var/log/timeline.log
respawn
#!/usr/bin/ruby
require "tweetstream"
require "optparse"
require "yaml"
require "json"
usage = "Usage: timeline-logger [--config FILE]\n\nOptions:"
config_filename = "/opt/timeline-logger/etc/config.yml"
opts = OptionParser.new do |opts|
opts.banner = usage
opts.on("--config FILE", "path to the configuration file.") do |filename|
config_filename = filename
end
end
begin
opts.parse!
rescue OptionParser::InvalidOption
$stderr.puts "timeline-logger: #{$!.message}"
$stderr.puts "timeline-logger: try `timeline-logger --help` for more information."
exit 1
end
config = YAML.load(IO.read(config_filename))
TweetStream.configure do |c|
c.consumer_key = config["auth"]["consumer_key"]
c.consumer_secret = config["auth"]["consumer_secret"]
c.oauth_token = config["auth"]["access_token"]
c.oauth_token_secret = config["auth"]["access_token_secret"]
c.auth_method = :oauth
end
client = TweetStream::Client.new
client.on("anything") do |hash|
$stdout.puts hash.to_json
$stdout.flush
end
client.userstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment