class TweetWatch::CLI

Public Instance Methods

limits() click to toggle source
# File lib/tweet_watch/cli.rb, line 18
def limits
  load_config(options)
  resp = Twitter::REST::Request.new(client, 'get', "/1.1/application/rate_limit_status.json" ).perform
  
  current_time = Time.now.to_i
  template = "   %-40s %5d remaining, resets in %3d seconds\n"
  resp.body[:resources].each do |category,resources|
    puts category.to_s
    resources.each do |resource,info|
      printf template, resource.to_s, info[:remaining], info[:reset] - current_time
    end
  end
end
monitor() click to toggle source
# File lib/tweet_watch/cli.rb, line 109
def monitor      
  load_config(options)
  m = TweetWatch::Monitor.new(options)
  m.run        
end
timeline() click to toggle source
# File lib/tweet_watch/cli.rb, line 37
def timeline
  load_config(options)
  
  if options[:stream]
    sc = streaming_client(options)
    puts "Starting stream...".colorize(:light_cyan)
    sc.user do |obj|
      if obj.class == Twitter::Tweet
        print_tweet obj
      elsif obj.class == Twitter::DirectMessage
        print_dm obj
      end
    end
  else
    opts = {count: options[:count]}
    client(options).home_timeline(opts).each do |tw|
      print_tweet(tw)
    end
  end 
  
end
watch() click to toggle source
# File lib/tweet_watch/cli.rb, line 66
def watch
  load_config(options)
          
  sc = streaming_client(options)
  file = CSV.open(options[:output], "wb")
  tw_config = TweetWatch.config
  
  tweeters = options[:tweeters] ? options[:tweeters] : tw_config.tweeters
  
  unless File.size(options[:output]) > 0
    file << %W(timelined_at tweet_id screen_name text tweet_created_at is_reply is_quote)
  end
        
  puts "Starting stream...".colorize(:light_cyan)
  sc.user do |obj|
    time = Time.now
    
    if obj.class == Twitter::Tweet          
      if options[:tweeters_only].nil? || (options[:tweeters_only] && tweeters.include?(obj.account.screen_name))
        print_tweet obj
      end
      
      if tw_config.tweeters.empty? || tw_config.has_tweeter?(obj.user.screen_name)
        puts "recording tweet data".colorize(:red)            
        file << [time.utc, obj.id, obj.user.screen_name, obj.text,obj.created_at.getutc,obj.user.screen_name, obj.reply?, obj.quote?]
        file.flush
      end
    elsif obj.class == Twitter::DirectMessage
      print_dm obj
    elsif obj.class == Twitter::Streaming::StallWarning
      warn "Falling behind!"
    else
      # do nothing for now
      #puts "untracked tweet obj #{obj.class}".colorize(color: :black, background: :light_white)
    end
  
  end
end