Skip to content

Commit

Permalink
Migrate stream subcommands to locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerine committed May 29, 2012
1 parent 734bb2a commit 3335fd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
12 changes: 12 additions & 0 deletions lib/t/locales/en.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -349,3 +349,15 @@ en:


stream: stream:
desc: "Commands for streaming Tweets." desc: "Commands for streaming Tweets."

all:
desc: "Stream a random sample of all Tweets (Control-C to stop)"

search:
desc: "Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)"

timeline:
desc: "Stream your timeline (Control-C to stop)"

users:
desc: "Stream Tweets either from or in reply to specified users (Control-C to stop)"
28 changes: 15 additions & 13 deletions lib/t/stream.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ module T
autoload :Printable, 't/printable' autoload :Printable, 't/printable'
autoload :RCFile, 't/rcfile' autoload :RCFile, 't/rcfile'
autoload :Search, 't/search' autoload :Search, 't/search'
autoload :Translations, "t/translations"
class Stream < Thor class Stream < Thor
include T::Printable include T::Printable
include T::Translations


STATUS_HEADINGS_FORMATTING = [ STATUS_HEADINGS_FORMATTING = [
"%-18s", # Add padding to maximum length of a Tweet ID "%-18s", # Add padding to maximum length of a Tweet ID
Expand All @@ -20,9 +22,9 @@ def initialize(*)
@rcfile = RCFile.instance @rcfile = RCFile.instance
end end


desc "all", "Stream a random sample of all Tweets (Control-C to stop)" desc "all", I18n.t("tasks.stream.all.desc")
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format." method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.csv")
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format." method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.long")
def all def all
require 'tweetstream' require 'tweetstream'
client.on_inited do client.on_inited do
Expand Down Expand Up @@ -52,7 +54,7 @@ def all
client.sample client.sample
end end


desc "matrix", "Unfortunately, no one can be told what the Matrix is. You have to see it for yourself." desc "matrix", I18n.t("tasks.matrix.desc")
def matrix def matrix
require 'tweetstream' require 'tweetstream'
client.on_timeline_status do |status| client.on_timeline_status do |status|
Expand All @@ -61,9 +63,9 @@ def matrix
client.sample client.sample
end end


desc "search KEYWORD [KEYWORD...]", "Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)" desc "search KEYWORD [KEYWORD...]", I18n.t("tasks.stream.search.desc")
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format." method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.csv")
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format." method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.long")
def search(keyword, *keywords) def search(keyword, *keywords)
keywords.unshift(keyword) keywords.unshift(keyword)
require 'tweetstream' require 'tweetstream'
Expand All @@ -89,9 +91,9 @@ def search(keyword, *keywords)
client.track(keywords) client.track(keywords)
end end


desc "timeline", "Stream your timeline (Control-C to stop)" desc "timeline", I18n.t("tasks.stream.timeline.desc")
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format." method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.csv")
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format." method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.long")
def timeline def timeline
require 'tweetstream' require 'tweetstream'
client.on_inited do client.on_inited do
Expand All @@ -116,9 +118,9 @@ def timeline
client.userstream client.userstream
end end


desc "users USER_ID [USER_ID...]", "Stream Tweets either from or in reply to specified users (Control-C to stop)" desc "users USER_ID [USER_ID...]", I18n.t("tasks.stream.users.desc")
method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => "Output in CSV format." method_option "csv", :aliases => "-c", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.csv")
method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => "Output in long format." method_option "long", :aliases => "-l", :type => :boolean, :default => false, :desc => I18n.t("tasks.common_options.long")
def users(user_id, *user_ids) def users(user_id, *user_ids)
user_ids.unshift(user_id) user_ids.unshift(user_id)
user_ids.map!(&:to_i) user_ids.map!(&:to_i)
Expand Down

0 comments on commit 3335fd7

Please sign in to comment.