Sha256: ffddfb5ad837fee4c3d440fac99186848355745fc7d0070af6c4c52126d8f969
Contents?: true
Size: 1.4 KB
Versions: 12
Compression:
Stored size: 1.4 KB
Contents
#!/usr/bin/env ruby #$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'chatterbot' require 'optparse' include Chatterbot::Helpers include Chatterbot::Config include Chatterbot::DB @tweet_count = 5 # # pull in any arguments and set them as env variables # opts = OptionParser.new opts.banner = "Usage: #{File.basename($0)} [options]" opts.separator "" opts.separator "Specific options:" opts.on('-d', '--db [ARG]', "Specify a DB connection URI") { |d| ENV["chatterbot_db"] = d } opts.on('-c', '--config [ARG]', "Specify a config file to use") { |c| ENV["chatterbot_config"] = c } opts.on('-t', '--tweets [ARG]', "How many tweets to display") { |t| @tweet_count = t.to_i } opts.on_tail("-h", "--help", "Show this message") do puts opts exit end extra = opts.parse!(ARGV) # # will only work if user is tracking tweets in a db # if ! has_db? puts "You need to specify a db connection!" exit end # # return total number of tweets sent in last 'days' days # def count_for_period(bot, days=1) db[:tweets].filter(:bot => bot[:id]).filter{created_at > (Time.now - (days*86400))}.count end db[:config].each do |bot| puts "Tweets from #{bot[:id]} #{[1,7,30].collect{|d| count_for_period(bot, d)}.join("/")}" db[:tweets].filter(:bot => bot[:id]).order(:created_at.desc).limit(@tweet_count).each do |t| puts "#{t[:created_at]}: #{t[:txt]} (#{t[:source_tweet]})" end end
Version data entries
12 entries across 12 versions & 1 rubygems