t 3.1.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE.md +1 -1
- data/README.md +8 -9
- data/bin/t +21 -21
- data/lib/t/cli.rb +470 -463
- data/lib/t/collectable.rb +9 -8
- data/lib/t/core_ext/kernel.rb +3 -3
- data/lib/t/core_ext/string.rb +2 -2
- data/lib/t/delete.rb +44 -41
- data/lib/t/editor.rb +5 -5
- data/lib/t/identicon.rb +1 -1
- data/lib/t/list.rb +51 -51
- data/lib/t/printable.rb +69 -65
- data/lib/t/rcfile.rb +18 -17
- data/lib/t/requestable.rb +3 -2
- data/lib/t/search.rb +82 -82
- data/lib/t/set.rb +21 -21
- data/lib/t/stream.rb +67 -60
- data/lib/t/utils.rb +25 -25
- data/lib/t/version.rb +2 -2
- data/lib/t.rb +2 -2
- data/t.gemspec +22 -21
- metadata +29 -49
data/lib/t/search.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "thor"
|
2
|
+
require "twitter"
|
3
|
+
require "t/collectable"
|
4
|
+
require "t/printable"
|
5
|
+
require "t/rcfile"
|
6
|
+
require "t/requestable"
|
7
|
+
require "t/utils"
|
8
8
|
|
9
9
|
module T
|
10
10
|
class Search < Thor
|
@@ -24,52 +24,52 @@ module T
|
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
27
|
-
desc
|
28
|
-
method_option
|
29
|
-
method_option
|
30
|
-
method_option
|
31
|
-
method_option
|
32
|
-
method_option
|
27
|
+
desc "all QUERY", "Returns the #{DEFAULT_NUM_RESULTS} most recent Tweets that match the specified query."
|
28
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
29
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
30
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
31
|
+
method_option "number", aliases: "-n", type: :numeric, default: DEFAULT_NUM_RESULTS
|
32
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
33
33
|
def all(query)
|
34
|
-
count = options[
|
34
|
+
count = options["number"] || DEFAULT_NUM_RESULTS
|
35
35
|
opts = {count: MAX_SEARCH_RESULTS}
|
36
|
-
opts[:include_entities] = !!options[
|
36
|
+
opts[:include_entities] = !!options["decode_uris"]
|
37
37
|
tweets = client.search(query, opts).take(count)
|
38
|
-
tweets.reverse! if options[
|
39
|
-
if options[
|
40
|
-
require
|
38
|
+
tweets.reverse! if options["reverse"]
|
39
|
+
if options["csv"]
|
40
|
+
require "csv"
|
41
41
|
say TWEET_HEADINGS.to_csv unless tweets.empty?
|
42
42
|
tweets.each do |tweet|
|
43
|
-
say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet, options[
|
43
|
+
say [tweet.id, csv_formatted_time(tweet), tweet.user.screen_name, decode_full_text(tweet, options["decode_uris"])].to_csv
|
44
44
|
end
|
45
|
-
elsif options[
|
45
|
+
elsif options["long"]
|
46
46
|
array = tweets.collect do |tweet|
|
47
|
-
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options[
|
47
|
+
[tweet.id, ls_formatted_time(tweet), "@#{tweet.user.screen_name}", decode_full_text(tweet, options["decode_uris"]).gsub(/\n+/, " ")]
|
48
48
|
end
|
49
|
-
format = options[
|
49
|
+
format = options["format"] || Array.new(TWEET_HEADINGS.size) { "%s" }
|
50
50
|
print_table_with_headings(array, TWEET_HEADINGS, format)
|
51
51
|
else
|
52
52
|
say unless tweets.empty?
|
53
53
|
tweets.each do |tweet|
|
54
|
-
print_message(tweet.user.screen_name, decode_full_text(tweet, options[
|
54
|
+
print_message(tweet.user.screen_name, decode_full_text(tweet, options["decode_uris"]))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
desc
|
60
|
-
method_option
|
61
|
-
method_option
|
62
|
-
method_option
|
63
|
-
method_option
|
64
|
-
method_option
|
59
|
+
desc "favorites [USER] QUERY", "Returns Tweets you've favorited that match the specified query."
|
60
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
61
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
62
|
+
method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
|
63
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
64
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
65
65
|
def favorites(*args)
|
66
66
|
query = args.pop
|
67
67
|
user = args.pop
|
68
68
|
opts = {count: MAX_NUM_RESULTS}
|
69
|
-
opts[:include_entities] = !!options[
|
69
|
+
opts[:include_entities] = !!options["decode_uris"]
|
70
70
|
if user
|
71
|
-
require
|
72
|
-
user = options[
|
71
|
+
require "t/core_ext/string"
|
72
|
+
user = options["id"] ? user.to_i : user.strip_ats
|
73
73
|
tweets = collect_with_max_id do |max_id|
|
74
74
|
opts[:max_id] = max_id unless max_id.nil?
|
75
75
|
client.favorites(user, opts)
|
@@ -85,18 +85,18 @@ module T
|
|
85
85
|
end
|
86
86
|
print_tweets(tweets)
|
87
87
|
end
|
88
|
-
map %w
|
88
|
+
map %w[faves] => :favorites
|
89
89
|
|
90
|
-
desc
|
91
|
-
method_option
|
92
|
-
method_option
|
93
|
-
method_option
|
94
|
-
method_option
|
95
|
-
method_option
|
90
|
+
desc "list [USER/]LIST QUERY", "Returns Tweets on a list that match the specified query."
|
91
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
92
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
93
|
+
method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
|
94
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
95
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
96
96
|
def list(user_list, query)
|
97
97
|
owner, list_name = extract_owner(user_list, options)
|
98
98
|
opts = {count: MAX_NUM_RESULTS}
|
99
|
-
opts[:include_entities] = !!options[
|
99
|
+
opts[:include_entities] = !!options["decode_uris"]
|
100
100
|
tweets = collect_with_max_id do |max_id|
|
101
101
|
opts[:max_id] = max_id unless max_id.nil?
|
102
102
|
client.list_timeline(owner, list_name, opts)
|
@@ -107,14 +107,14 @@ module T
|
|
107
107
|
print_tweets(tweets)
|
108
108
|
end
|
109
109
|
|
110
|
-
desc
|
111
|
-
method_option
|
112
|
-
method_option
|
113
|
-
method_option
|
114
|
-
method_option
|
110
|
+
desc "mentions QUERY", "Returns Tweets mentioning you that match the specified query."
|
111
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
112
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
113
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
114
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
115
115
|
def mentions(query)
|
116
116
|
opts = {count: MAX_NUM_RESULTS}
|
117
|
-
opts[:include_entities] = !!options[
|
117
|
+
opts[:include_entities] = !!options["decode_uris"]
|
118
118
|
tweets = collect_with_max_id do |max_id|
|
119
119
|
opts[:max_id] = max_id unless max_id.nil?
|
120
120
|
client.mentions(opts)
|
@@ -124,22 +124,22 @@ module T
|
|
124
124
|
end
|
125
125
|
print_tweets(tweets)
|
126
126
|
end
|
127
|
-
map %w
|
127
|
+
map %w[replies] => :mentions
|
128
128
|
|
129
|
-
desc
|
130
|
-
method_option
|
131
|
-
method_option
|
132
|
-
method_option
|
133
|
-
method_option
|
134
|
-
method_option
|
129
|
+
desc "retweets [USER] QUERY", "Returns Tweets you've retweeted that match the specified query."
|
130
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
131
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
132
|
+
method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
|
133
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
134
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
135
135
|
def retweets(*args)
|
136
136
|
query = args.pop
|
137
137
|
user = args.pop
|
138
138
|
opts = {count: MAX_NUM_RESULTS}
|
139
|
-
opts[:include_entities] = !!options[
|
139
|
+
opts[:include_entities] = !!options["decode_uris"]
|
140
140
|
if user
|
141
|
-
require
|
142
|
-
user = options[
|
141
|
+
require "t/core_ext/string"
|
142
|
+
user = options["id"] ? user.to_i : user.strip_ats
|
143
143
|
tweets = collect_with_max_id do |max_id|
|
144
144
|
opts[:max_id] = max_id unless max_id.nil?
|
145
145
|
client.retweeted_by_user(user, opts)
|
@@ -155,29 +155,29 @@ module T
|
|
155
155
|
end
|
156
156
|
print_tweets(tweets)
|
157
157
|
end
|
158
|
-
map %w
|
158
|
+
map %w[rts] => :retweets
|
159
159
|
|
160
|
-
desc
|
161
|
-
method_option
|
162
|
-
method_option
|
163
|
-
method_option
|
164
|
-
method_option
|
165
|
-
method_option
|
166
|
-
method_option
|
167
|
-
method_option
|
168
|
-
method_option
|
160
|
+
desc "timeline [USER] QUERY", "Returns Tweets in your timeline that match the specified query."
|
161
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
162
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
163
|
+
method_option "exclude", aliases: "-e", type: :string, enum: %w[replies retweets], desc: "Exclude certain types of Tweets from the results.", banner: "TYPE"
|
164
|
+
method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
|
165
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
166
|
+
method_option "max_id", aliases: "-m", type: :numeric, desc: "Returns only the results with an ID less than the specified ID."
|
167
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
168
|
+
method_option "since_id", aliases: "-s", type: :numeric, desc: "Returns only the results with an ID greater than the specified ID."
|
169
169
|
def timeline(*args)
|
170
170
|
query = args.pop
|
171
171
|
user = args.pop
|
172
172
|
opts = {count: MAX_NUM_RESULTS}
|
173
|
-
opts[:exclude_replies] = true if options[
|
174
|
-
opts[:include_entities] = !!options[
|
175
|
-
opts[:include_rts] = false if options[
|
176
|
-
opts[:max_id] = options[
|
177
|
-
opts[:since_id] = options[
|
173
|
+
opts[:exclude_replies] = true if options["exclude"] == "replies"
|
174
|
+
opts[:include_entities] = !!options["decode_uris"]
|
175
|
+
opts[:include_rts] = false if options["exclude"] == "retweets"
|
176
|
+
opts[:max_id] = options["max_id"] if options["max_id"]
|
177
|
+
opts[:since_id] = options["since_id"] if options["since_id"]
|
178
178
|
if user
|
179
|
-
require
|
180
|
-
user = options[
|
179
|
+
require "t/core_ext/string"
|
180
|
+
user = options["id"] ? user.to_i : user.strip_ats
|
181
181
|
tweets = collect_with_max_id do |max_id|
|
182
182
|
opts[:max_id] = max_id unless max_id.nil?
|
183
183
|
client.user_timeline(user, opts)
|
@@ -193,18 +193,18 @@ module T
|
|
193
193
|
end
|
194
194
|
print_tweets(tweets)
|
195
195
|
end
|
196
|
-
map %w
|
196
|
+
map %w[tl] => :timeline
|
197
197
|
|
198
|
-
desc
|
199
|
-
method_option
|
200
|
-
method_option
|
201
|
-
method_option
|
202
|
-
method_option
|
203
|
-
method_option
|
204
|
-
method_option
|
198
|
+
desc "users QUERY", "Returns users that match the specified query."
|
199
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
200
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
201
|
+
method_option "relative_dates", aliases: "-a", type: :boolean, desc: "Show relative dates."
|
202
|
+
method_option "reverse", aliases: "-r", type: :boolean, desc: "Reverse the order of the sort."
|
203
|
+
method_option "sort", aliases: "-s", type: :string, enum: %w[favorites followers friends listed screen_name since tweets tweeted], default: "screen_name", desc: "Specify the order of the results.", banner: "ORDER"
|
204
|
+
method_option "unsorted", aliases: "-u", type: :boolean, desc: "Output is not sorted."
|
205
205
|
def users(query)
|
206
206
|
users = collect_with_page do |page|
|
207
|
-
client.user_search(query, page:
|
207
|
+
client.user_search(query, page:)
|
208
208
|
end
|
209
209
|
print_users(users)
|
210
210
|
end
|
data/lib/t/set.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "thor"
|
2
|
+
require "t/rcfile"
|
3
|
+
require "t/requestable"
|
4
4
|
|
5
5
|
module T
|
6
6
|
class Set < Thor
|
@@ -13,57 +13,57 @@ module T
|
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
16
|
-
desc
|
16
|
+
desc "active SCREEN_NAME [CONSUMER_KEY]", "Set your active account."
|
17
17
|
def active(screen_name, consumer_key = nil)
|
18
|
-
require
|
18
|
+
require "t/core_ext/string"
|
19
19
|
screen_name = screen_name.strip_ats
|
20
|
-
@rcfile.path = options[
|
20
|
+
@rcfile.path = options["profile"] if options["profile"]
|
21
21
|
consumer_key = @rcfile[screen_name].keys.last if consumer_key.nil?
|
22
|
-
@rcfile.active_profile = {
|
22
|
+
@rcfile.active_profile = {"username" => @rcfile[screen_name][consumer_key]["username"], "consumer_key" => consumer_key}
|
23
23
|
say "Active account has been updated to #{@rcfile.active_profile[0]}."
|
24
24
|
end
|
25
|
-
map %w
|
25
|
+
map %w[account default] => :active
|
26
26
|
|
27
|
-
desc
|
27
|
+
desc "bio DESCRIPTION", "Edits your Bio information on your Twitter profile."
|
28
28
|
def bio(description)
|
29
|
-
client.update_profile(description:
|
29
|
+
client.update_profile(description:)
|
30
30
|
say "@#{@rcfile.active_profile[0]}'s bio has been updated."
|
31
31
|
end
|
32
32
|
|
33
|
-
desc
|
33
|
+
desc "language LANGUAGE_NAME", "Selects the language you'd like to receive notifications in."
|
34
34
|
def language(language_name)
|
35
35
|
client.settings(lang: language_name)
|
36
36
|
say "@#{@rcfile.active_profile[0]}'s language has been updated."
|
37
37
|
end
|
38
38
|
|
39
|
-
desc
|
39
|
+
desc "location PLACE_NAME", "Updates the location field in your profile."
|
40
40
|
def location(place_name)
|
41
41
|
client.update_profile(location: place_name)
|
42
42
|
say "@#{@rcfile.active_profile[0]}'s location has been updated."
|
43
43
|
end
|
44
44
|
|
45
|
-
desc
|
45
|
+
desc "name NAME", "Sets the name field on your Twitter profile."
|
46
46
|
def name(name)
|
47
|
-
client.update_profile(name:
|
47
|
+
client.update_profile(name:)
|
48
48
|
say "@#{@rcfile.active_profile[0]}'s name has been updated."
|
49
49
|
end
|
50
50
|
|
51
|
-
desc
|
52
|
-
method_option
|
51
|
+
desc "profile_background_image FILE", "Sets the background image on your Twitter profile."
|
52
|
+
method_option "tile", aliases: "-t", type: :boolean, desc: "Whether or not to tile the background image."
|
53
53
|
def profile_background_image(file)
|
54
|
-
client.update_profile_background_image(File.new(File.expand_path(file)), tile: options[
|
54
|
+
client.update_profile_background_image(File.new(File.expand_path(file)), tile: options["tile"], skip_status: true)
|
55
55
|
say "@#{@rcfile.active_profile[0]}'s background image has been updated."
|
56
56
|
end
|
57
|
-
map %w
|
57
|
+
map %w[background background_image] => :profile_background_image
|
58
58
|
|
59
|
-
desc
|
59
|
+
desc "profile_image FILE", "Sets the image on your Twitter profile."
|
60
60
|
def profile_image(file)
|
61
61
|
client.update_profile_image(File.new(File.expand_path(file)))
|
62
62
|
say "@#{@rcfile.active_profile[0]}'s image has been updated."
|
63
63
|
end
|
64
|
-
map %w
|
64
|
+
map %w[avatar image] => :profile_image
|
65
65
|
|
66
|
-
desc
|
66
|
+
desc "website URI", "Sets the website field on your profile."
|
67
67
|
def website(uri)
|
68
68
|
client.update_profile(url: uri)
|
69
69
|
say "@#{@rcfile.active_profile[0]}'s website has been updated."
|
data/lib/t/stream.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "thor"
|
2
|
+
require "t/printable"
|
3
|
+
require "t/rcfile"
|
4
|
+
require "t/requestable"
|
5
|
+
require "t/utils"
|
6
6
|
|
7
7
|
module T
|
8
8
|
class Stream < Thor
|
@@ -11,10 +11,10 @@ module T
|
|
11
11
|
include T::Utils
|
12
12
|
|
13
13
|
TWEET_HEADINGS_FORMATTING = [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
"%-18s", # Add padding to maximum length of a Tweet ID
|
15
|
+
"%-12s", # Add padding to length of a timestamp formatted with ls_formatted_time
|
16
|
+
"%-20s", # Add padding to maximum length of a Twitter screen name
|
17
|
+
"%s", # Last element does not need special formatting
|
18
18
|
].freeze
|
19
19
|
|
20
20
|
check_unknown_options!
|
@@ -24,16 +24,16 @@ module T
|
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
27
|
-
desc
|
28
|
-
method_option
|
29
|
-
method_option
|
30
|
-
method_option
|
27
|
+
desc "all", "Stream a random sample of all Tweets (Control-C to stop)"
|
28
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
29
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
30
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
31
31
|
def all
|
32
32
|
streaming_client.before_request do
|
33
|
-
if options[
|
34
|
-
require
|
33
|
+
if options["csv"]
|
34
|
+
require "csv"
|
35
35
|
say TWEET_HEADINGS.to_csv
|
36
|
-
elsif options[
|
36
|
+
elsif options["long"] && STDOUT.tty?
|
37
37
|
headings = Array.new(TWEET_HEADINGS.size) do |index|
|
38
38
|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
|
39
39
|
end
|
@@ -42,9 +42,10 @@ module T
|
|
42
42
|
end
|
43
43
|
streaming_client.sample do |tweet|
|
44
44
|
next unless tweet.is_a?(Twitter::Tweet)
|
45
|
-
|
45
|
+
|
46
|
+
if options["csv"]
|
46
47
|
print_csv_tweet(tweet)
|
47
|
-
elsif options[
|
48
|
+
elsif options["long"]
|
48
49
|
array = build_long_tweet(tweet).each_with_index.collect do |element, index|
|
49
50
|
TWEET_HEADINGS_FORMATTING[index] % element
|
50
51
|
end
|
@@ -55,15 +56,15 @@ module T
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
desc
|
59
|
-
method_option
|
60
|
-
method_option
|
61
|
-
method_option
|
62
|
-
method_option
|
63
|
-
method_option
|
59
|
+
desc "list [USER/]LIST", "Stream a timeline for members of the specified list (Control-C to stop)"
|
60
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
61
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
62
|
+
method_option "id", aliases: "-i", type: :boolean, desc: "Specify user via ID instead of screen name."
|
63
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
64
|
+
method_option "reverse", aliases: "-r", type: :boolean, desc: "Reverse the order of the sort."
|
64
65
|
def list(user_list)
|
65
66
|
owner, list_name = extract_owner(user_list, options)
|
66
|
-
require
|
67
|
+
require "t/list"
|
67
68
|
streaming_client.before_request do
|
68
69
|
list = T::List.new
|
69
70
|
list.options = list.options.merge(options)
|
@@ -72,11 +73,12 @@ module T
|
|
72
73
|
list.timeline(user_list)
|
73
74
|
end
|
74
75
|
user_ids = client.list_members(owner, list_name).collect(&:id)
|
75
|
-
streaming_client.filter(follow: user_ids.join(
|
76
|
+
streaming_client.filter(follow: user_ids.join(",")) do |tweet|
|
76
77
|
next unless tweet.is_a?(Twitter::Tweet)
|
77
|
-
|
78
|
+
|
79
|
+
if options["csv"]
|
78
80
|
print_csv_tweet(tweet)
|
79
|
-
elsif options[
|
81
|
+
elsif options["long"]
|
80
82
|
array = build_long_tweet(tweet).each_with_index.collect do |element, index|
|
81
83
|
TWEET_HEADINGS_FORMATTING[index] % element
|
82
84
|
end
|
@@ -86,40 +88,42 @@ module T
|
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
89
|
-
map %w
|
91
|
+
map %w[tl] => :timeline
|
90
92
|
|
91
|
-
desc
|
93
|
+
desc "matrix", "Unfortunately, no one can be told what the Matrix is. You have to see it for yourself."
|
92
94
|
def matrix
|
93
|
-
require
|
95
|
+
require "t/cli"
|
94
96
|
streaming_client.before_request do
|
95
97
|
cli = T::CLI.new
|
96
98
|
cli.matrix
|
97
99
|
end
|
98
|
-
streaming_client.sample(language:
|
100
|
+
streaming_client.sample(language: "ja") do |tweet|
|
99
101
|
next unless tweet.is_a?(Twitter::Tweet)
|
100
|
-
|
102
|
+
|
103
|
+
say(tweet.text.gsub(/[^\u3000\u3040-\u309f]/, "").reverse, %i[bold green on_black], false)
|
101
104
|
end
|
102
105
|
end
|
103
106
|
|
104
|
-
desc
|
105
|
-
method_option
|
106
|
-
method_option
|
107
|
-
method_option
|
107
|
+
desc "search KEYWORD [KEYWORD...]", "Stream Tweets that contain specified keywords, joined with logical ORs (Control-C to stop)"
|
108
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
109
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
110
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
108
111
|
def search(keyword, *keywords)
|
109
112
|
keywords.unshift(keyword)
|
110
|
-
require
|
113
|
+
require "t/search"
|
111
114
|
streaming_client.before_request do
|
112
115
|
search = T::Search.new
|
113
116
|
search.options = search.options.merge(options)
|
114
117
|
search.options = search.options.merge(reverse: true)
|
115
118
|
search.options = search.options.merge(format: TWEET_HEADINGS_FORMATTING)
|
116
|
-
search.all(keywords.join(
|
119
|
+
search.all(keywords.join(" OR "))
|
117
120
|
end
|
118
|
-
streaming_client.filter(track: keywords.join(
|
121
|
+
streaming_client.filter(track: keywords.join(",")) do |tweet|
|
119
122
|
next unless tweet.is_a?(Twitter::Tweet)
|
120
|
-
|
123
|
+
|
124
|
+
if options["csv"]
|
121
125
|
print_csv_tweet(tweet)
|
122
|
-
elsif options[
|
126
|
+
elsif options["long"]
|
123
127
|
array = build_long_tweet(tweet).each_with_index.collect do |element, index|
|
124
128
|
TWEET_HEADINGS_FORMATTING[index] % element
|
125
129
|
end
|
@@ -130,12 +134,12 @@ module T
|
|
130
134
|
end
|
131
135
|
end
|
132
136
|
|
133
|
-
desc
|
134
|
-
method_option
|
135
|
-
method_option
|
136
|
-
method_option
|
137
|
+
desc "timeline", "Stream your timeline (Control-C to stop)"
|
138
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
139
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
140
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
137
141
|
def timeline
|
138
|
-
require
|
142
|
+
require "t/cli"
|
139
143
|
streaming_client.before_request do
|
140
144
|
cli = T::CLI.new
|
141
145
|
cli.options = cli.options.merge(options)
|
@@ -145,9 +149,10 @@ module T
|
|
145
149
|
end
|
146
150
|
streaming_client.user do |tweet|
|
147
151
|
next unless tweet.is_a?(Twitter::Tweet)
|
148
|
-
|
152
|
+
|
153
|
+
if options["csv"]
|
149
154
|
print_csv_tweet(tweet)
|
150
|
-
elsif options[
|
155
|
+
elsif options["long"]
|
151
156
|
array = build_long_tweet(tweet).each_with_index.collect do |element, index|
|
152
157
|
TWEET_HEADINGS_FORMATTING[index] % element
|
153
158
|
end
|
@@ -158,29 +163,30 @@ module T
|
|
158
163
|
end
|
159
164
|
end
|
160
165
|
|
161
|
-
desc
|
162
|
-
method_option
|
163
|
-
method_option
|
164
|
-
method_option
|
166
|
+
desc "users USER_ID [USER_ID...]", "Stream Tweets either from or in reply to specified users (Control-C to stop)"
|
167
|
+
method_option "csv", aliases: "-c", type: :boolean, desc: "Output in CSV format."
|
168
|
+
method_option "decode_uris", aliases: "-d", type: :boolean, desc: "Decodes t.co URLs into their original form."
|
169
|
+
method_option "long", aliases: "-l", type: :boolean, desc: "Output in long format."
|
165
170
|
def users(user_id, *user_ids)
|
166
171
|
user_ids.unshift(user_id)
|
167
172
|
user_ids.collect!(&:to_i)
|
168
173
|
streaming_client.before_request do
|
169
|
-
if options[
|
170
|
-
require
|
174
|
+
if options["csv"]
|
175
|
+
require "csv"
|
171
176
|
say TWEET_HEADINGS.to_csv
|
172
|
-
elsif options[
|
177
|
+
elsif options["long"] && STDOUT.tty?
|
173
178
|
headings = Array.new(TWEET_HEADINGS.size) do |index|
|
174
179
|
TWEET_HEADINGS_FORMATTING[index] % TWEET_HEADINGS[index]
|
175
180
|
end
|
176
181
|
print_table([headings])
|
177
182
|
end
|
178
183
|
end
|
179
|
-
streaming_client.filter(follow: user_ids.join(
|
184
|
+
streaming_client.filter(follow: user_ids.join(",")) do |tweet|
|
180
185
|
next unless tweet.is_a?(Twitter::Tweet)
|
181
|
-
|
186
|
+
|
187
|
+
if options["csv"]
|
182
188
|
print_csv_tweet(tweet)
|
183
|
-
elsif options[
|
189
|
+
elsif options["long"]
|
184
190
|
array = build_long_tweet(tweet).each_with_index.collect do |element, index|
|
185
191
|
TWEET_HEADINGS_FORMATTING[index] % element
|
186
192
|
end
|
@@ -195,7 +201,8 @@ module T
|
|
195
201
|
|
196
202
|
def streaming_client
|
197
203
|
return @streaming_client if @streaming_client
|
198
|
-
|
204
|
+
|
205
|
+
@rcfile.path = options["profile"] if options["profile"]
|
199
206
|
@streaming_client = Twitter::Streaming::Client.new do |config|
|
200
207
|
config.consumer_key = @rcfile.active_consumer_key
|
201
208
|
config.consumer_secret = @rcfile.active_consumer_secret
|