earthquake 0.9.0 → 0.9.1
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.
- data/README.md +31 -0
- data/bin/earthquake +2 -0
- data/lib/earthquake/commands.rb +36 -1
- data/lib/earthquake/core.rb +48 -23
- data/lib/earthquake/ext.rb +1 -1
- data/lib/earthquake/input.rb +6 -6
- data/lib/earthquake/output.rb +1 -1
- data/lib/earthquake/version.rb +2 -2
- metadata +9 -3
data/README.md
CHANGED
@@ -142,6 +142,37 @@ Commands
|
|
142
142
|
# return to normal user stream
|
143
143
|
⚡ :filter off
|
144
144
|
|
145
|
+
### Show config
|
146
|
+
|
147
|
+
# All config
|
148
|
+
⚡ :config
|
149
|
+
|
150
|
+
# config for :key
|
151
|
+
⚡ :config key
|
152
|
+
|
153
|
+
### Set config
|
154
|
+
|
155
|
+
# set config for :key to (evaluated) value
|
156
|
+
⚡ :config key 1 + 1
|
157
|
+
{
|
158
|
+
:key => 2
|
159
|
+
}
|
160
|
+
⚡ :config key {foo: 1, bar: 2}
|
161
|
+
{
|
162
|
+
:key => {
|
163
|
+
:foo => 1,
|
164
|
+
:bar => 2
|
165
|
+
}
|
166
|
+
}
|
167
|
+
# merge new config if both are Hash
|
168
|
+
⚡ :config key {bar: 3}
|
169
|
+
{
|
170
|
+
:key => {
|
171
|
+
:foo => 1,
|
172
|
+
:bar => 3
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
145
176
|
And more!
|
146
177
|
|
147
178
|
Configuration
|
data/bin/earthquake
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
gem 'slop', '~> 2.0'
|
2
3
|
require 'slop'
|
3
4
|
|
4
5
|
argv = ARGV.dup
|
@@ -7,6 +8,7 @@ slop.banner "Usage: earthquake [options] [directory]"
|
|
7
8
|
slop.on :d, :debug, 'Enable debug mode'
|
8
9
|
slop.on :n, :'no-logo', 'No Logo'
|
9
10
|
slop.on :c, :command, "Invoke a command and exit", true
|
11
|
+
slop.on :'--no-stream', "No stream mode"
|
10
12
|
begin
|
11
13
|
slop.parse!(argv)
|
12
14
|
rescue => e
|
data/lib/earthquake/commands.rb
CHANGED
@@ -42,6 +42,29 @@ Earthquake.init do
|
|
42
42
|
⚡ :help :retweet
|
43
43
|
HELP
|
44
44
|
|
45
|
+
# :config
|
46
|
+
|
47
|
+
command :config do
|
48
|
+
ap config
|
49
|
+
end
|
50
|
+
|
51
|
+
command :config do |m|
|
52
|
+
key, value = m[1].split(/\s+/, 2)
|
53
|
+
key = key.to_sym
|
54
|
+
if value
|
55
|
+
value = eval(value)
|
56
|
+
preferred_config.store(key, value)
|
57
|
+
reload
|
58
|
+
end
|
59
|
+
ap config.slice(key)
|
60
|
+
end
|
61
|
+
|
62
|
+
help :config, 'show or set config', <<-HELP
|
63
|
+
⚡ :config
|
64
|
+
⚡ :config key
|
65
|
+
⚡ :config key value
|
66
|
+
HELP
|
67
|
+
|
45
68
|
# :restart
|
46
69
|
|
47
70
|
command :restart do
|
@@ -85,16 +108,28 @@ Earthquake.init do
|
|
85
108
|
⚡ :aa :status $aa
|
86
109
|
HELP
|
87
110
|
|
111
|
+
def self._eval_as_ruby_string(text)
|
112
|
+
return text unless config[:eval_as_ruby_string_for_update]
|
113
|
+
begin
|
114
|
+
text = eval(%|"#{text.gsub('"', '\"')}"|)
|
115
|
+
rescue Exception => e
|
116
|
+
puts e.message.c(:notice)
|
117
|
+
end
|
118
|
+
text
|
119
|
+
end
|
120
|
+
|
88
121
|
command %r|^:update$|, :as => :update do
|
89
122
|
puts "[input EOF (e.g. Ctrl+D) at the last]".c(:info)
|
90
123
|
text = STDIN.gets(nil)
|
124
|
+
text = _eval_as_ruby_string(text)
|
91
125
|
if text && !text.split.empty?
|
92
126
|
async_e{ twitter.update(text) } if confirm("update above AA?")
|
93
127
|
end
|
94
128
|
end
|
95
129
|
|
96
130
|
command :update do |m|
|
97
|
-
|
131
|
+
text = _eval_as_ruby_string(m[1])
|
132
|
+
async_e { twitter.update(text) } if confirm("update '#{text}'")
|
98
133
|
end
|
99
134
|
|
100
135
|
command %r|^[^:\$].*| do |m|
|
data/lib/earthquake/core.rb
CHANGED
@@ -7,6 +7,10 @@ module Earthquake
|
|
7
7
|
@config ||= {}
|
8
8
|
end
|
9
9
|
|
10
|
+
def preferred_config
|
11
|
+
@preferred_config ||= {}
|
12
|
+
end
|
13
|
+
|
10
14
|
def item_queue
|
11
15
|
@item_queue ||= []
|
12
16
|
end
|
@@ -49,22 +53,29 @@ module Earthquake
|
|
49
53
|
_init
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
56
|
+
def default_config
|
53
57
|
consumer = YAML.load_file(File.expand_path('../../../consumer.yml', __FILE__))
|
58
|
+
dir = config[:dir] || File.expand_path('~/.earthquake')
|
59
|
+
{
|
60
|
+
dir: dir,
|
61
|
+
time_format: Time::DATE_FORMATS[:short],
|
62
|
+
plugin_dir: File.join(dir, 'plugin'),
|
63
|
+
file: File.join(dir, 'config'),
|
64
|
+
prompt: '⚡ ',
|
65
|
+
consumer_key: consumer['key'],
|
66
|
+
consumer_secret: consumer['secret'],
|
67
|
+
output_interval: 1,
|
68
|
+
history_size: 1000,
|
69
|
+
api: { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true },
|
70
|
+
confirm_type: :y,
|
71
|
+
expand_url: false,
|
72
|
+
thread_indent: " ",
|
73
|
+
no_data_timeout: 30
|
74
|
+
}
|
75
|
+
end
|
54
76
|
|
55
|
-
|
56
|
-
config
|
57
|
-
config[:plugin_dir] ||= File.join(config[:dir], 'plugin')
|
58
|
-
config[:file] ||= File.join(config[:dir], 'config')
|
59
|
-
config[:prompt] ||= '⚡ '
|
60
|
-
config[:consumer_key] ||= consumer['key']
|
61
|
-
config[:consumer_secret] ||= consumer['secret']
|
62
|
-
config[:output_interval] ||= 1
|
63
|
-
config[:history_size] ||= 1000
|
64
|
-
config[:api] ||= { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true }
|
65
|
-
config[:confirm_type] ||= :y
|
66
|
-
config[:expand_url] ||= false
|
67
|
-
config[:thread_indent] ||= " "
|
77
|
+
def load_config
|
78
|
+
config.reverse_update(default_config)
|
68
79
|
|
69
80
|
[config[:dir], config[:plugin_dir]].each do |dir|
|
70
81
|
unless File.exists?(dir)
|
@@ -75,7 +86,15 @@ module Earthquake
|
|
75
86
|
if File.exists?(config[:file])
|
76
87
|
load config[:file]
|
77
88
|
else
|
78
|
-
File.open(config[:file], 'w')
|
89
|
+
File.open(config[:file], mode: 'w', perm: 0600).close
|
90
|
+
end
|
91
|
+
|
92
|
+
config.update(preferred_config) do |key, cur, new|
|
93
|
+
if Hash === cur and Hash === new
|
94
|
+
cur.merge(new)
|
95
|
+
else
|
96
|
+
new
|
97
|
+
end
|
79
98
|
end
|
80
99
|
|
81
100
|
get_access_token unless self.config[:token] && self.config[:secret]
|
@@ -106,7 +125,7 @@ module Earthquake
|
|
106
125
|
__init(options)
|
107
126
|
restore_history
|
108
127
|
|
109
|
-
|
128
|
+
EM.run do
|
110
129
|
Thread.start do
|
111
130
|
while buf = Readline.readline(config[:prompt], true)
|
112
131
|
unless Readline::HISTORY.count == 1
|
@@ -118,19 +137,24 @@ module Earthquake
|
|
118
137
|
input(buf.strip)
|
119
138
|
}
|
120
139
|
end
|
140
|
+
# unexpected
|
121
141
|
stop
|
122
142
|
end
|
123
143
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
144
|
+
EM.add_periodic_timer(config[:output_interval]) do
|
145
|
+
if @last_data_received_at && Time.now - @last_data_received_at > config[:no_data_timeout]
|
146
|
+
begin
|
147
|
+
reconnect
|
148
|
+
rescue EventMachine::ConnectionError => e
|
149
|
+
error(e)
|
128
150
|
end
|
129
|
-
|
151
|
+
end
|
152
|
+
if Readline.line_buffer.blank?
|
153
|
+
sync { output }
|
130
154
|
end
|
131
155
|
end
|
132
156
|
|
133
|
-
reconnect
|
157
|
+
reconnect unless options[:'no-stream'] == true
|
134
158
|
|
135
159
|
trap('INT') { stop }
|
136
160
|
end
|
@@ -154,6 +178,7 @@ module Earthquake
|
|
154
178
|
@stream = ::Twitter::JSONStream.connect(options)
|
155
179
|
|
156
180
|
@stream.each_item do |item|
|
181
|
+
@last_data_received_at = Time.now # for reconnect when no data
|
157
182
|
item_queue << JSON.parse(item)
|
158
183
|
end
|
159
184
|
|
@@ -176,7 +201,7 @@ module Earthquake
|
|
176
201
|
|
177
202
|
def stop
|
178
203
|
stop_stream
|
179
|
-
|
204
|
+
EM.stop_event_loop
|
180
205
|
end
|
181
206
|
|
182
207
|
def store_history
|
data/lib/earthquake/ext.rb
CHANGED
data/lib/earthquake/input.rb
CHANGED
@@ -124,12 +124,12 @@ module Earthquake
|
|
124
124
|
|
125
125
|
completion do |text|
|
126
126
|
regexp = /^#{Regexp.quote(text)}/
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
r | line.split.grep(regexp)
|
132
|
-
|
127
|
+
if text.start_with?(?:) && Readline.line_buffer.strip == text
|
128
|
+
(command_names + command_aliases.keys).grep(regexp)
|
129
|
+
else
|
130
|
+
history = Readline::HISTORY.reverse_each.take(config[:history_size]) | @tweets_for_completion
|
131
|
+
history.inject([]){ |r, line| r | line.split.grep(regexp) }
|
132
|
+
end
|
133
133
|
end
|
134
134
|
|
135
135
|
@tweets_for_completion ||= []
|
data/lib/earthquake/output.rb
CHANGED
@@ -151,7 +151,7 @@ module Earthquake
|
|
151
151
|
screen_name = twitter.info["screen_name"]
|
152
152
|
text = "(direct message)"
|
153
153
|
end
|
154
|
-
puts "%s %s: %s" % ["[delete]"
|
154
|
+
puts ("%s %s: %s" % ["[delete]", screen_name, text]).c(:info)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
data/lib/earthquake/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Earthquake
|
2
|
-
VERSION = '0.9.
|
3
|
-
end
|
2
|
+
VERSION = '0.9.1'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: earthquake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: twitter-stream
|
@@ -231,15 +231,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
231
|
- - ! '>='
|
232
232
|
- !ruby/object:Gem::Version
|
233
233
|
version: '0'
|
234
|
+
segments:
|
235
|
+
- 0
|
236
|
+
hash: -948738165396907969
|
234
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
238
|
none: false
|
236
239
|
requirements:
|
237
240
|
- - ! '>='
|
238
241
|
- !ruby/object:Gem::Version
|
239
242
|
version: '0'
|
243
|
+
segments:
|
244
|
+
- 0
|
245
|
+
hash: -948738165396907969
|
240
246
|
requirements: []
|
241
247
|
rubyforge_project: earthquake
|
242
|
-
rubygems_version: 1.8.
|
248
|
+
rubygems_version: 1.8.23
|
243
249
|
signing_key:
|
244
250
|
specification_version: 3
|
245
251
|
summary: Terminal Twitter Client
|