twitter2jabber 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/TODO +1 -2
- data/bin/twitter2jabber +9 -2
- data/lib/twitter2jabber/version.rb +1 -1
- data/lib/twitter2jabber.rb +25 -18
- metadata +2 -2
data/README
CHANGED
data/TODO
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
- Jabber::ServerDisconnected in lib/twitter2jabber.rb:165 (??? => Jabber::ServerDisconnected < Jabber::JabberError)
|
2
1
|
- threading?
|
3
2
|
- 'direct message' command
|
4
|
-
- persistent cache
|
3
|
+
- persistent cache? (friends_timeline: since/since_id?)
|
5
4
|
- OAuth (register: http://twitter.com/oauth_clients/new)
|
6
5
|
- better interrupt handling (in loop mode)
|
7
6
|
- daemonize after asking for credentials (in loop mode)
|
data/bin/twitter2jabber
CHANGED
@@ -56,6 +56,7 @@ options = {
|
|
56
56
|
:template_dir => nil,
|
57
57
|
:loop => false,
|
58
58
|
:pause => nil,
|
59
|
+
:last => nil,
|
59
60
|
:verbose => false,
|
60
61
|
:debug => false
|
61
62
|
}
|
@@ -111,6 +112,12 @@ OptionParser.new { |opts|
|
|
111
112
|
options[:pause] = p
|
112
113
|
}
|
113
114
|
|
115
|
+
opts.separator ' '
|
116
|
+
|
117
|
+
opts.on('-S', '--since-id ID', 'Return tweets with status IDs greater than ID') { |i|
|
118
|
+
options[:last] = i
|
119
|
+
}
|
120
|
+
|
114
121
|
opts.separator ' '
|
115
122
|
opts.separator 'Generic options:'
|
116
123
|
|
@@ -163,9 +170,9 @@ begin
|
|
163
170
|
|
164
171
|
if options[:loop]
|
165
172
|
warn Process.pid if options[:verbose]
|
166
|
-
twitter2jabber.loop(recipients, options[:pause] || config[:pause])
|
173
|
+
twitter2jabber.loop(recipients, options[:pause] || config[:pause], options[:last])
|
167
174
|
else
|
168
|
-
twitter2jabber.run(recipients)
|
175
|
+
twitter2jabber.run(recipients, options[:last])
|
169
176
|
end
|
170
177
|
rescue RuntimeError => err
|
171
178
|
abort err
|
data/lib/twitter2jabber.rb
CHANGED
@@ -48,12 +48,12 @@ class Twitter2Jabber
|
|
48
48
|
JABBER_NS = 'http://jabber.org/protocol/xhtml-im'
|
49
49
|
XHTML_NS = 'http://www.w3.org/1999/xhtml'
|
50
50
|
|
51
|
-
def self.loop(options, recipients = [], pause = nil, &block)
|
52
|
-
new(options).loop(recipients, pause, &block)
|
51
|
+
def self.loop(options, recipients = [], pause = nil, last = nil, &block)
|
52
|
+
new(options).loop(recipients, pause, last, &block)
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.run(options, recipients = [], &block)
|
56
|
-
new(options).run(recipients, &block)
|
55
|
+
def self.run(options, recipients = [], last = nil, &block)
|
56
|
+
new(options).run(recipients, last, &block)
|
57
57
|
end
|
58
58
|
|
59
59
|
attr_reader :id, :verbose, :debug, :twitter, :jabber, :filter, :formats, :templates, :_erb
|
@@ -88,15 +88,17 @@ class Twitter2Jabber
|
|
88
88
|
}
|
89
89
|
end
|
90
90
|
|
91
|
-
def run(recipients = [],
|
92
|
-
deliver_tweets(recipients,
|
91
|
+
def run(recipients = [], last = nil, flag = true, &block)
|
92
|
+
last = deliver_tweets(recipients, last, &block) if flag
|
93
93
|
post_messages(recipients)
|
94
|
+
|
95
|
+
last
|
94
96
|
end
|
95
97
|
|
96
|
-
def loop(recipients = [], pause = nil, &block)
|
98
|
+
def loop(recipients = [], pause = nil, last = nil, &block)
|
97
99
|
pause ||= DEFAULT_PAUSE
|
98
100
|
|
99
|
-
i
|
101
|
+
i = 1
|
100
102
|
|
101
103
|
trap(:INT) {
|
102
104
|
log 'SIGINT received, shutting down...'
|
@@ -104,7 +106,7 @@ class Twitter2Jabber
|
|
104
106
|
}
|
105
107
|
|
106
108
|
while i > 0
|
107
|
-
run(recipients,
|
109
|
+
last = run(recipients, last, i % pause == 1, &block)
|
108
110
|
|
109
111
|
sleep 1
|
110
112
|
|
@@ -112,13 +114,13 @@ class Twitter2Jabber
|
|
112
114
|
end
|
113
115
|
|
114
116
|
log 'KTHXBYE!'
|
115
|
-
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
next if seen[tweet.id]
|
118
|
+
last
|
119
|
+
end
|
120
120
|
|
121
|
-
|
121
|
+
def deliver_tweets(recipients, last = nil, &block)
|
122
|
+
get_tweets(last).each { |tweet|
|
123
|
+
logt last = tweet.id
|
122
124
|
|
123
125
|
# apply filters
|
124
126
|
next if filter && !filter[tweet]
|
@@ -132,6 +134,8 @@ class Twitter2Jabber
|
|
132
134
|
|
133
135
|
sleep 1
|
134
136
|
}
|
137
|
+
|
138
|
+
last
|
135
139
|
end
|
136
140
|
|
137
141
|
def post_messages(recipients = [])
|
@@ -173,8 +177,11 @@ class Twitter2Jabber
|
|
173
177
|
raise "Can't connect to Jabber with JID '#{options[:user]}': #{err}"
|
174
178
|
end
|
175
179
|
|
176
|
-
def get_tweets
|
177
|
-
|
180
|
+
def get_tweets(last = nil)
|
181
|
+
options = {}
|
182
|
+
options[:since_id] = last if last
|
183
|
+
|
184
|
+
tweets = twitter.friends_timeline(options)
|
178
185
|
return [] unless tweets.is_a?(Array)
|
179
186
|
|
180
187
|
tweets.sort_by { |tweet|
|
@@ -224,8 +231,8 @@ class Twitter2Jabber
|
|
224
231
|
end
|
225
232
|
|
226
233
|
def process_html(text)
|
227
|
-
text.gsub(/(
|
228
|
-
gsub(/(
|
234
|
+
text.gsub(/(\A|\W)@(\w+)/, '\1@<a href="http://twitter.com/\2">\2</a>').
|
235
|
+
gsub(/(\A|\W)#(\w+)/, '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>')
|
229
236
|
end
|
230
237
|
|
231
238
|
def process_text(text)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter2jabber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-13 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|