diff options
author | wjoe <joe@lc8n.com> | 2012-02-07 13:12:19 +0000 |
---|---|---|
committer | wjoe <joe@lc8n.com> | 2012-02-07 13:12:19 +0000 |
commit | 0218fc53a41c95dd64fdb6f41ace854b580b72a3 (patch) | |
tree | 99f7b933bf9fa9a0a354c37e2d3c1e7a49bc270f | |
parent | a3a4709eb1e4b9d98b8c174ee809995ed1d8a72a (diff) |
Historic commit 1.0.4 (02-Feb-2012 17:49)
-rw-r--r-- | blatweet.rb | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/blatweet.rb b/blatweet.rb index fd9106c..5777126 100644 --- a/blatweet.rb +++ b/blatweet.rb @@ -2,10 +2,14 @@ require 'twitter' require 'optparse' +output = [] + username = nil number_of_tweets = 1 -output = [] -version = 1.03 +limit = false +version = 'v1.0.4' +help = false +ops = nil STDIN.gets.split(' ').each{|arg| ARGV << arg} if ARGV == [] args = ARGV.dup @@ -14,32 +18,40 @@ options = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} -u USERNAME -n NO_OF_TWEETS" opts.on( "-u", "--username USERNAME", "Twitter username to search for." ) { |u| username = u } opts.on( "-n", "--number NO_OF_TWEETS", "Number of tweets to return." ) { |n| number_of_tweets = n } - opts.on( '-h', '--help', 'Display this screen' ) { puts opts; exit } - opts.on( '-l', '--limit', 'Display remaining hits' ) { puts Twitter.rate_limit_status.remaining_hits.to_s + " tweets remaining."; exit } - opts.on( '-v', '--version', 'Display program version' ) { puts version } + opts.on( '-l', '--limit', 'Display remaining hits' ) { limit = true } + opts.on( "-v", "--version", "blatweet version number." ) { puts version; exit } + opts.on( '-h', '--help', 'Display this screen.' ) { help = true; ops = opts } end;options.parse! if args == [] - puts options + puts "Usage: #{File.basename($0)} -h" exit(-1) end -twitter_config = YAML::load( File.open( 'config.yaml' ) ) +begin + + twitter_config = YAML::load( File.open( 'config.yaml' ) ) -Twitter.configure do |config| - config.consumer_key = twitter_config[:consumer_key] - config.consumer_secret = twitter_config[:consumer_secret] - config.oauth_token = twitter_config[:oauth_token] - config.oauth_token_secret = twitter_config[:oauth_token_secret] -end + Twitter.configure do |config| + config.consumer_key = twitter_config[:consumer_key] + config.consumer_secret = twitter_config[:consumer_secret] + config.oauth_token = twitter_config[:oauth_token] + config.oauth_token_secret = twitter_config[:oauth_token_secret] + end -begin - if username + if help + ops.to_s.split(/\n\s*|\s{2,}/).each{|opt| output << opt} + puts output.join(' ') + elsif limit + remaining_calls = Twitter.rate_limit_status.remaining_hits + puts remaining_calls == 0 ? "Limit reached. Limit resets in #{60 - Time.now.min} minutes." : "Remaining calls this hour: #{remaining_calls}. #{remaining_calls/(60 - Time.now.min)} calls/minute." + elsif username Twitter.search("from:#{username}", :rpp => number_of_tweets, :result_type => "recent").each_with_index{|tweet, index| output << "#{index+1}: #{tweet.text}"} puts output.join ' ' else Twitter.update ARGV.join ' ' end + rescue Twitter::Error => e puts e.message rescue StandardError => e |