diff --git a/History.txt b/History.txt index fc6d446a7..6be14fc24 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +0.3.1 - July 23, 2008 + * added open to CLI twitter open jnunemaker would open default browser to http://twitter.com/jnunemaker + * added -f to timeline and replies which ignores the since_id and shows all results + * added clear_config to remove all cached since id's and such + 0.3.0 - July 22, 2008 * complete rewrite of CLI. Now supports multiple accounts and changing between them. * added source, truncated, in_reply_to_status_id, in_reply_to_user_id, and favorited to Twitter::Status diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 000000000..5ac13d796 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,3 @@ +* format the tweets in a more readable fashion (limit words per line so more scannable) +* add timeout so it doesn't hang forever like it does now if twitter is down +* add progress indicator for timeline and replies as posting has for more visual indication that work is happening \ No newline at end of file diff --git a/lib/twitter/cli.rb b/lib/twitter/cli.rb index f6adf09ab..5d311dded 100644 --- a/lib/twitter/cli.rb +++ b/lib/twitter/cli.rb @@ -253,45 +253,57 @@ def run description 'the timeline you wish to see (friends, public, me)' default 'friends' } + option('force', 'f') { + description "Ignore since_id and show first page of results even if there aren't new ones" + } def run do_work do timeline = params['timeline'].value == 'me' ? 'user' : params['timeline'].value options, since_id = {}, Configuration["#{timeline}_last_id"] - options[:since_id] = since_id unless since_id.blank? - statuses = base.timeline(timeline.to_sym, options) - username_length = statuses.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0 - if statuses.size > 0 - statuses.each do |s| - Tweet.create_from_tweet(current_account, s) if timeline != :public - say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}" - end - Configuration["#{timeline}_last_id"] = statuses.first.id - else - say 'Nothing new since your last check' - end + options[:since_id] = since_id if !since_id.blank? && !params['force'].given? + cache = [:friends, :user].include?(timeline) + collection = base.timeline(timeline.to_sym, options) + output_tweets(collection, {:cache => cache, :since_prefix => timeline}) end end end mode 'replies' do description 'Allows you to view all @replies at you' + option('force', 'f') { + description "Ignore since_id and show first page of replies even if there aren't new ones" + } def run do_work do options, since_id = {}, Configuration["replies_since_id"] - options[:since_id] = since_id if !since_id.blank? - replies = base.replies(options) - username_length = replies.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0 - if replies.size > 0 - replies.each do |s| - say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}" - end - Configuration["replies_since_id"] = replies.first.id - else - say 'No new replies since your last check' - end + options[:since_id] = since_id if !since_id.blank? && !params['force'].given? + collection = base.replies(options) + output_tweets(collection, {:since_prefix => 'replies'}) + end + end + end + + mode 'clear_config' do + def run + do_work do + count = Configuration.count + Configuration.destroy_all + say("#{count} configuration entries cleared.") end end end + + mode 'open' do + description 'Opens the given twitter user in a browser window' + argument('username') { + required + description "username or id of twitterrer who's page you would like to see" + } + + def run + `open http://twitter.com/#{params['username'].value}` + end + end } diff --git a/lib/twitter/cli/helpers.rb b/lib/twitter/cli/helpers.rb index 0b3f17663..4586fbcbc 100644 --- a/lib/twitter/cli/helpers.rb +++ b/lib/twitter/cli/helpers.rb @@ -1,6 +1,24 @@ module Twitter module CLI module Helpers + def output_tweets(collection, options={}) + options.reverse_merge!({ + :cache => false, + :since_prefix => '', + :empty_msg => 'Nothing new since your last check.' + }) + if collection.size > 0 + username_length = collect.collect { |s| s.user.screen_name }.max { |a,b| a.length <=> b.length }.length rescue 0 + collection.each do |s| + Tweet.create_from_tweet(current_account, s) if options[:cache] + say "#{CGI::unescapeHTML(s.user.screen_name.ljust(username_length+1))}: #{CGI::unescapeHTML(s.text)} -- on #{Time.parse(s.created_at).strftime('%b %d at %l:%M%P')}" + end + Configuration["#{options[:since_prefix]}_since_id"] = collection.first.id + else + say(options[:empty_msg]) + end + end + def base(username=current_account.username, password=current_account.password) @base ||= Twitter::Base.new(username, password) end diff --git a/lib/twitter/version.rb b/lib/twitter/version.rb index ef2a2be54..93d72cf2c 100644 --- a/lib/twitter/version.rb +++ b/lib/twitter/version.rb @@ -2,7 +2,7 @@ module Twitter #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 3 - TINY = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end