#!/usr/bin/env ruby require 'twitter' require 'optparse' username = nil number_of_tweets = 1 STDIN.gets.split(' ').each{|arg| ARGV << arg} if ARGV == [] args = ARGV.dup 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 } end;options.parse! if args == [] puts options exit(-1) end Twitter.configure do |config| config.consumer_key = 'vXaBVIrxiJw2TKVJyI1w' config.consumer_secret = 'Xrg8ezA461OlLP94951kWxONMs9CkDCVkW25KZICjY8' config.oauth_token = '143847685-6uQb9mhDCqhNASYtsi6ZwZoO3Am5Yq2IbPtcjUJ0' config.oauth_token_secret = 'YxnmXtywSbIvJHyX6pdGhDnkQiR2Z1KJ84DQyzVpUk' end if username Twitter.search("from:#{username}", :rpp => number_of_tweets, :result_type => "recent").each{|tweet| puts tweet.text} else Twitter.update ARGV.join ' ' end