earthquake 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -4
- data/VERSION +1 -1
- data/earthquake.gemspec +1 -1
- data/lib/earthquake/commands.rb +5 -0
- data/lib/earthquake/core.rb +68 -36
- data/lib/earthquake/output.rb +7 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -91,13 +91,12 @@ The 'm' is a MatchData.
|
|
91
91
|
TODO
|
92
92
|
----
|
93
93
|
|
94
|
-
* plugin system
|
95
94
|
* filter
|
96
|
-
*
|
97
|
-
* show more events
|
98
|
-
* show retweeted status id
|
95
|
+
* plugin system
|
99
96
|
* keyword tracking
|
100
97
|
* more intelligent completion
|
98
|
+
* spec
|
99
|
+
* typable id
|
101
100
|
|
102
101
|
Copyright
|
103
102
|
----
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/earthquake.gemspec
CHANGED
data/lib/earthquake/commands.rb
CHANGED
@@ -11,6 +11,7 @@ module Earthquake
|
|
11
11
|
|
12
12
|
command :restart do
|
13
13
|
puts 'restarting...'
|
14
|
+
stop
|
14
15
|
exec File.expand_path('../../..//bin/earthquake', __FILE__)
|
15
16
|
end
|
16
17
|
|
@@ -95,5 +96,9 @@ module Earthquake
|
|
95
96
|
command :report_spam do |m|
|
96
97
|
twitter.report_spam(m[1])
|
97
98
|
end
|
99
|
+
|
100
|
+
command :reconnect do
|
101
|
+
reconnect
|
102
|
+
end
|
98
103
|
end
|
99
104
|
end
|
data/lib/earthquake/core.rb
CHANGED
@@ -54,58 +54,90 @@ module Earthquake
|
|
54
54
|
|
55
55
|
def start(*argv)
|
56
56
|
_init
|
57
|
+
restore_history
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
EventMachine::run do
|
60
|
+
Thread.start do
|
61
|
+
while buf = Readline.readline("⚡ ", true)
|
62
|
+
Readline::HISTORY.pop if buf.empty?
|
63
|
+
input(buf.strip)
|
64
|
+
end
|
61
65
|
end
|
62
|
-
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
Thread.start do
|
68
|
+
loop do
|
69
|
+
if Readline.line_buffer.nil? || Readline.line_buffer.empty?
|
70
|
+
output
|
71
|
+
sleep 1
|
72
|
+
else
|
73
|
+
sleep 2
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
77
|
+
|
78
|
+
reconnect
|
79
|
+
|
80
|
+
trap('TERM') { stop }
|
73
81
|
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def reconnect
|
85
|
+
item_queue.clear
|
86
|
+
start_stream(:host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true)
|
87
|
+
end
|
88
|
+
|
89
|
+
def start_stream(options)
|
90
|
+
stop_stream
|
74
91
|
|
75
|
-
|
76
|
-
|
77
|
-
:
|
78
|
-
:host => 'userstream.twitter.com',
|
79
|
-
:path => '/2/user.json',
|
80
|
-
:oauth => config.slice(:consumer_key, :consumer_secret).merge(:access_key => config[:token], :access_secret => config[:secret])
|
92
|
+
options = {
|
93
|
+
:oauth => config.slice(:consumer_key, :consumer_secret).merge(
|
94
|
+
:access_key => config[:token], :access_secret => config[:secret]
|
81
95
|
)
|
96
|
+
}.merge(options)
|
82
97
|
|
83
|
-
|
84
|
-
item_queue << JSON.parse(item)
|
85
|
-
end
|
98
|
+
@stream = ::Twitter::JSONStream.connect(options)
|
86
99
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
100
|
+
@stream.each_item do |item|
|
101
|
+
item_queue << JSON.parse(item)
|
102
|
+
end
|
91
103
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
104
|
+
@stream.on_error do |message|
|
105
|
+
notify "error: #{message}"
|
106
|
+
end
|
96
107
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
108
|
+
@stream.on_reconnect do |timeout, retries|
|
109
|
+
notify "reconnecting in: #{timeout} seconds"
|
110
|
+
end
|
101
111
|
|
102
|
-
|
103
|
-
|
112
|
+
@stream.on_max_reconnects do |timeout, retries|
|
113
|
+
notify "Failed after #{retries} failed reconnects"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def stop_stream
|
118
|
+
@stream.stop if @stream
|
104
119
|
end
|
105
120
|
|
106
121
|
def stop
|
107
|
-
|
108
|
-
EventMachine.
|
122
|
+
stop_stream
|
123
|
+
EventMachine.stop_event_loop
|
124
|
+
store_history
|
125
|
+
end
|
126
|
+
|
127
|
+
def store_history
|
128
|
+
history_size = config[:history_size] || 1000
|
129
|
+
File.open(File.join(config[:dir], 'history'), 'w') do |file|
|
130
|
+
lines = Readline::HISTORY.to_a[([Readline::HISTORY.size - history_size, 0].max)..-1]
|
131
|
+
puts lines
|
132
|
+
file.print(lines.join("\n"))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def restore_history
|
137
|
+
history_file = File.join(config[:dir], 'history')
|
138
|
+
if File.exists?(history_file)
|
139
|
+
File.read(history_file).split(/\n/).each { |line| Readline::HISTORY << line }
|
140
|
+
end
|
109
141
|
end
|
110
142
|
|
111
143
|
def notify(message)
|
data/lib/earthquake/output.rb
CHANGED
@@ -59,7 +59,13 @@ module Earthquake
|
|
59
59
|
output_hander do |item|
|
60
60
|
next unless item["text"]
|
61
61
|
|
62
|
-
|
62
|
+
if item["in_reply_to_status_id"]
|
63
|
+
misc = " (reply to #{item["in_reply_to_status_id"]})"
|
64
|
+
elsif item["retweeted_status"]
|
65
|
+
misc = " (retweet of #{item["retweeted_status"]["id"]})"
|
66
|
+
else
|
67
|
+
misc = ""
|
68
|
+
end
|
63
69
|
source = item["source"] =~ />(.*)</ ? $1 : 'web'
|
64
70
|
user_color = color_of(item["user"]["screen_name"])
|
65
71
|
text = item["text"].e.gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
|