Created
February 16, 2014 11:48
-
-
Save nojima/9032975 to your computer and use it in GitHub Desktop.
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
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 |
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/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