Sha256: a9a2f09957af6f4cdcbb2af8bca66fa616816e9792d973e86962363a200e35d5

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 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

Chatterbot::from_helper = true

@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

7 entries across 7 versions & 1 rubygems

Version Path
chatterbot-1.0.2 bin/chatterbot-status
chatterbot-1.0.1 bin/chatterbot-status
chatterbot-1.0.0 bin/chatterbot-status
chatterbot-0.9.3 bin/chatterbot-status
chatterbot-0.9.2 bin/chatterbot-status
chatterbot-0.9.1 bin/chatterbot-status
chatterbot-0.9.0 bin/chatterbot-status