Sha256: d0bcffee1687f2f800b06d472ef5d14c0cb7e5adbc6942505c9663de6b2aec09

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

#!/usr/bin/env ruby

require "tweetskim"
require "optparse"


def parse_options
  options = {}

  OptionParser.new do |o|
   #TODO o.on("-a", "--show-all", "Show all tweets, not just unread ones (max 300)") { |b| options[:show_all] = b } 
    o.on("-e", "--mentions", "Show mentions instead of timeline") { |b| options[:mentions] = b }
    o.on("-i", "--inverse-order", "Inverse/reverse ordered tweets") { |b| options[:inverse_order] = b }
    o.on("-h", "--help", "Help page") { puts o; exit }
   #TODO  o.on("-m", "--mark-all-read", "Mark everything up to now as read") { |b| options[:mark_all_read] = b }
    o.on("-n N", "--last-n-tweets N", "Show only the last N tweets") { |n| options[:last_n_tweets] = n }
    o.on("-o MODE", "--output-mode MODE", "Output as 'lines', 'column' or 'html'") { |mode| options[:output_mode] = mode }
   #TODO  o.on("-u USER", "--user USER", "Which twitter user I am. Example: tweetskim -u thomanil") { |u| options[:user] = u }
    o.on("-v", "--version", "Spit out version") { |b| puts Tweetskim::VERSION; exit }

    o.parse!
  end

  return options
end

def fetch_tweets(options = {})
  adapter = Tweetskim::TwitterAdapter.new

  if options[:mentions]
    tweets = adapter.mentions(:count => options[:last_n_tweets] || 300)
  else
    tweets = adapter.timeline(:count => options[:last_n_tweets] || 300)
  end

   if options[:inverse_order]
     tweets = tweets.reverse
   end

  return tweets
end

def write_tweets_to_stdout(tweets, options = {})
  formatter = Tweetskim::Formatter.new
  output_mode = options[:output_mode]

  if !output_mode || output_mode == "lines"
    result = formatter.lines(tweets, options)
  elsif output_mode == "column"
    result = formatter.column(tweets, {:width => 40})
  elsif output_mode == "html"
    puts "Html mode not done yet."; exit
  else
    puts "Invalid output mode."
    exit
  end
  
  puts result
end


options = parse_options
tweets = fetch_tweets(options)
write_tweets_to_stdout(tweets, options)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tweetskim-0.2.0 bin/tweetskim