Class: TweetWatch::CLI
- Inherits:
-
Thor
- Object
- Thor
- TweetWatch::CLI
show all
- Includes:
- Client, Utils
- Defined in:
- lib/tweet_watch/cli.rb
Instance Method Summary
collapse
Methods included from Utils
#escape_str, #load_config, #print_dm, #print_tweet
Methods included from Client
#client, #streaming_client
Instance Method Details
#limits ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/tweet_watch/cli.rb', line 18
def limits
load_config(options)
resp = ::REST::Request.new(client, 'get', "/1.1/application/rate_limit_status.json" ).perform
current_time = Time.now.to_i
template = " %-40s %5d remaining, resets in %3d seconds\n"
resp.body[:resources].each do |category,resources|
puts category.to_s
resources.each do |resource,info|
printf template, resource.to_s, info[:remaining], info[:reset] - current_time
end
end
end
|
#monitor ⇒ Object
109
110
111
112
113
|
# File 'lib/tweet_watch/cli.rb', line 109
def monitor
load_config(options)
m = ::Monitor.new(options)
m.run
end
|
#timeline ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/tweet_watch/cli.rb', line 37
def timeline
load_config(options)
if options[:stream]
sc = streaming_client(options)
puts "Starting stream...".colorize(:light_cyan)
sc.user do |obj|
if obj.class == ::
obj
elsif obj.class == ::DirectMessage
print_dm obj
end
end
else
opts = {count: options[:count]}
client(options).home_timeline(opts).each do |tw|
(tw)
end
end
end
|
#watch ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/tweet_watch/cli.rb', line 66
def watch
load_config(options)
sc = streaming_client(options)
file = CSV.open(options[:output], "wb")
tw_config = .config
= options[:tweeters] ? options[:tweeters] : tw_config.
unless File.size(options[:output]) > 0
file << %W(timelined_at tweet_id screen_name text tweet_created_at is_reply is_quote)
end
puts "Starting stream...".colorize(:light_cyan)
sc.user do |obj|
time = Time.now
if obj.class == ::
if options[:tweeters_only].nil? || (options[:tweeters_only] && .include?(obj.account.screen_name))
obj
end
if tw_config..empty? || tw_config.(obj.user.screen_name)
puts "recording tweet data".colorize(:red)
file << [time.utc, obj.id, obj.user.screen_name, obj.text,obj.created_at.getutc,obj.user.screen_name, obj.reply?, obj.quote?]
file.flush
end
elsif obj.class == ::DirectMessage
print_dm obj
elsif obj.class == ::Streaming::StallWarning
warn "Falling behind!"
else
end
end
end
|