Created
December 8, 2017 03:22
-
-
Save masao/9881dd72c90b968d908944b10a034772 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require "yaml" | |
require "twitter" | |
require 'ruby-growl' | |
if $0 == __FILE__ | |
g = Growl::GNTP.new( "localhost", "ruby-growl" ) | |
if g.notifications.empty? | |
g.add_notification( "notification" ) | |
g.register | |
end | |
q = ARGV[0] || "#klis_stat" | |
STDERR.puts "Query: #{ q }" | |
config_file = "twitter.yml" | |
config = YAML.load( open( config_file ) )["test"] | |
username = config["login"] | |
client = Twitter::REST::Client.new do |c| | |
c.consumer_key = config[ "oauth_consumer_token" ] | |
c.consumer_secret = config[ "oauth_consumer_secret" ] | |
c.access_token = config[ "oauth_token" ] | |
c.access_token_secret = config[ "oauth_token_secret" ] | |
end | |
since_id = nil | |
while true | |
results = begin | |
client.search( q, since_id: since_id, count: 10, exclude: "retweets" ) | |
rescue Twitter::Error, Twitter::Error::RequestTimeout | |
STDERR.puts "#{ $!.class }: #{ $!.message }" | |
STDERR.puts "skip... (#{ Time.now })" | |
sleep 60 | |
next | |
end | |
since_id = results.attrs[:search_metadata][:max_id] if not results.attrs[:statuses].empty? | |
results.take(20).each do |r| | |
g.notify( "notification", "Tweet from @#{r.user.screen_name} (#{ r.user.name })", | |
r.full_text, 0, false, nil, r.url ) | |
puts r.created_at.strftime( "%Y-%m-%d %H:%M:%S" ) | |
puts r.url | |
puts "From @#{r.user.screen_name} (#{ r.user.name }):" | |
puts r.full_text | |
end | |
puts | |
puts since_id | |
STDERR.puts "next... (#{ Time.now })" | |
sleep 6 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment