earthquake 0.4.4 → 0.4.5
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 +9 -0
- data/VERSION +1 -1
- data/earthquake.gemspec +1 -1
- data/lib/earthquake/commands.rb +20 -5
- data/lib/earthquake/core.rb +1 -0
- data/lib/earthquake/ext.rb +24 -0
- data/lib/earthquake/input.rb +3 -3
- data/lib/earthquake/output.rb +9 -7
- data/lib/earthquake/twitter.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -7,6 +7,13 @@ It supports ruby 1.9 only.
|
|
7
7
|
|
8
8
|

|
9
9
|
|
10
|
+
Features
|
11
|
+
----
|
12
|
+
|
13
|
+
* You can deal Twitter on Terminal entirely.
|
14
|
+
* You can receive data in real time with Streaming API.
|
15
|
+
* You can easily extend in Ruby.
|
16
|
+
|
10
17
|
Install
|
11
18
|
----
|
12
19
|
|
@@ -150,6 +157,8 @@ The 'm' is a MatchData.
|
|
150
157
|
TODO
|
151
158
|
----
|
152
159
|
|
160
|
+
* unescape html
|
161
|
+
* dealing direct messages
|
153
162
|
* more intelligent completion
|
154
163
|
* caching statuses
|
155
164
|
* typable id
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
data/earthquake.gemspec
CHANGED
data/lib/earthquake/commands.rb
CHANGED
@@ -25,10 +25,13 @@ module Earthquake
|
|
25
25
|
end
|
26
26
|
|
27
27
|
command %r|^:reply (\d+)\s+(.*)|, :as => :reply do |m|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
in_reply_to_status_id = m[1]
|
29
|
+
target = twitter.status(in_reply_to_status_id)
|
30
|
+
screen_name = target["user"]["screen_name"]
|
31
|
+
text = "@#{screen_name} #{m[2]}"
|
32
|
+
if confirm(["'@#{screen_name}: #{target["text"].u}'".c(36), "reply '#{text}'"].join("\n"))
|
33
|
+
async { twitter.update(text, :in_reply_to_status_id => in_reply_to_status_id) }
|
34
|
+
end
|
32
35
|
end
|
33
36
|
|
34
37
|
command :status do |m|
|
@@ -56,6 +59,10 @@ module Earthquake
|
|
56
59
|
puts_items twitter.user_timeline(:screen_name => m[1]).reverse
|
57
60
|
end
|
58
61
|
|
62
|
+
command :home do
|
63
|
+
puts_items twitter.home_timeline.reverse
|
64
|
+
end
|
65
|
+
|
59
66
|
command :user do |m|
|
60
67
|
ap twitter.show(m[1]).slice(*%w(id screen_name name profile_image_url description url location time_zone lang protected))
|
61
68
|
end
|
@@ -64,7 +71,15 @@ module Earthquake
|
|
64
71
|
puts_items twitter.search(m[1])["results"].each { |s|
|
65
72
|
s["user"] = {"screen_name" => s["from_user"]}
|
66
73
|
}.each {|s|
|
67
|
-
|
74
|
+
words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x|
|
75
|
+
case x
|
76
|
+
when /^from:(.+)/, /^to:(.+)/
|
77
|
+
$1
|
78
|
+
else
|
79
|
+
x
|
80
|
+
end
|
81
|
+
}
|
82
|
+
s["highlights"] = words
|
68
83
|
}.reverse
|
69
84
|
end
|
70
85
|
|
data/lib/earthquake/core.rb
CHANGED
data/lib/earthquake/ext.rb
CHANGED
@@ -2,4 +2,28 @@ class String
|
|
2
2
|
def c(*codes)
|
3
3
|
"\e[#{codes.join;}m#{self}\e[0m"
|
4
4
|
end
|
5
|
+
|
6
|
+
def u
|
7
|
+
gsub(/&(lt|gt|amp|quot|apos);/) do |s|
|
8
|
+
case s
|
9
|
+
when '&' then '&'
|
10
|
+
when '<' then '<'
|
11
|
+
when '>' then '>'
|
12
|
+
when ''' then "'"
|
13
|
+
when '"' then '"'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def e
|
19
|
+
gsub(/[&<>'"]/) do |s|
|
20
|
+
case s
|
21
|
+
when '&' then '&'
|
22
|
+
when '<' then '<'
|
23
|
+
when '>' then '>'
|
24
|
+
when "'" then '''
|
25
|
+
when '"' then '"'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
5
29
|
end
|
data/lib/earthquake/input.rb
CHANGED
@@ -20,8 +20,8 @@ module Earthquake
|
|
20
20
|
def input(text)
|
21
21
|
begin
|
22
22
|
reload if config[:debug]
|
23
|
-
if command =
|
24
|
-
command[:block].call(
|
23
|
+
if command = command(text)
|
24
|
+
command[:block].call(command[:pattern].match(text))
|
25
25
|
elsif !text.empty?
|
26
26
|
puts "Command not found".c(43)
|
27
27
|
end
|
@@ -44,7 +44,7 @@ module Earthquake
|
|
44
44
|
command_names << ":#{options[:as]}" if options[:as]
|
45
45
|
commands << {:pattern => pattern, :block => block}
|
46
46
|
else
|
47
|
-
commands.detect {
|
47
|
+
commands.detect {|c| c[:pattern] =~ pattern}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
data/lib/earthquake/output.rb
CHANGED
@@ -21,7 +21,7 @@ module Earthquake
|
|
21
21
|
insert do
|
22
22
|
while item = item_queue.shift
|
23
23
|
item["stream"] = true
|
24
|
-
puts_items(item)
|
24
|
+
puts_items(item)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -29,9 +29,10 @@ module Earthquake
|
|
29
29
|
|
30
30
|
def puts_items(items)
|
31
31
|
[items].flatten.each do |item|
|
32
|
-
|
32
|
+
next if filters.any? { |f| f.call(item) == false }
|
33
|
+
outputs.each do |o|
|
33
34
|
begin
|
34
|
-
|
35
|
+
o.call(item)
|
35
36
|
rescue => e
|
36
37
|
error e
|
37
38
|
end
|
@@ -62,6 +63,7 @@ module Earthquake
|
|
62
63
|
|
63
64
|
init do
|
64
65
|
outputs.clear
|
66
|
+
filters.clear
|
65
67
|
|
66
68
|
config[:colors] ||= (31..36).to_a + (91..96).to_a
|
67
69
|
|
@@ -81,9 +83,9 @@ module Earthquake
|
|
81
83
|
statuses.insert(0, "[#{Time.parse(item["created_at"]).strftime('%Y.%m.%d %X')}]")
|
82
84
|
end
|
83
85
|
|
84
|
-
source = item["source"] =~ />(.*)</ ? $1 : 'web'
|
86
|
+
source = item["source"].u =~ />(.*)</ ? $1 : 'web'
|
85
87
|
user_color = color_of(item["user"]["screen_name"])
|
86
|
-
text = item["text"].gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
|
88
|
+
text = item["text"].u.gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
|
87
89
|
i.c(color_of($1))
|
88
90
|
end
|
89
91
|
|
@@ -99,8 +101,8 @@ module Earthquake
|
|
99
101
|
mark = item["mark"] || ""
|
100
102
|
|
101
103
|
status = [
|
102
|
-
"#{mark}#{statuses.join(" ")}".c(90),
|
103
|
-
item["user"]["screen_name"].c(user_color),
|
104
|
+
"#{mark}" + "#{statuses.join(" ")}".c(90),
|
105
|
+
"#{item["user"]["screen_name"].c(user_color)}:",
|
104
106
|
"#{text}",
|
105
107
|
"#{misc} #{source}".c(90)
|
106
108
|
].join(" ")
|
data/lib/earthquake/twitter.rb
CHANGED