twitter2jabber 0.1.8 → 0.1.9

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to twitter2jabber version 0.1.8
5
+ This documentation refers to twitter2jabber version 0.1.9
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ begin
16
16
  :homepage => %q{http://twitter2jabber.rubyforge.org/},
17
17
  :files => FileList['lib/**/*.rb', 'bin/*'].to_a,
18
18
  :extra_files => FileList['[A-Z]*', 'sample/**/*'].to_a,
19
- :dependencies => %w[twitter xmpp4r-simple highline shorturl longurl]
19
+ :dependencies => %w[twitter xmpp4r-simple highline shorturl longurl elif]
20
20
  }
21
21
  }}
22
22
  rescue LoadError
data/TODO CHANGED
@@ -1,4 +1,4 @@
1
- - threading?
1
+ - threading? (decouple Twitter and Jabber event loops)
2
2
  - 'direct message' command
3
3
  - persistent cache? (friends_timeline: since/since_id?)
4
4
  - OAuth (register: http://twitter.com/oauth_clients/new)
data/bin/twitter2jabber CHANGED
@@ -57,6 +57,8 @@ options = {
57
57
  :loop => false,
58
58
  :pause => nil,
59
59
  :last => nil,
60
+ :wrap => nil,
61
+ :log => STDERR,
60
62
  :verbose => false,
61
63
  :debug => false
62
64
  }
@@ -118,6 +120,13 @@ OptionParser.new { |opts|
118
120
  options[:last] = i
119
121
  }
120
122
 
123
+ opts.separator ' '
124
+
125
+ opts.on('-L', '--loop-wrap [LOG]', "Convenience switch: implies '--loop', '--verbose', and", "'--since-id'; kills existing process and logs output to LOG") { |l|
126
+ options[:wrap] = true
127
+ options[:log] = File.open(l, 'a') if l
128
+ }
129
+
121
130
  opts.separator ' '
122
131
  opts.separator 'Generic options:'
123
132
 
@@ -161,15 +170,54 @@ config[:jabber][:pass] ||= ask("Password for Jabber ID #{config[:jabber][:user]}
161
170
  recipients = options[:recipients] + (config.delete(:recipients) || [])
162
171
  recipients.uniq!
163
172
 
164
- [:formats, :template_dir, :verbose, :debug].each { |key|
173
+ [:formats, :template_dir, :log, :verbose, :debug].each { |key|
165
174
  config[key] = options[key] if options[key]
166
175
  }
167
176
 
168
177
  begin
178
+ if options[:wrap]
179
+ options[:loop] = true
180
+ options[:verbose] = true
181
+
182
+ case log = config[:log]
183
+ when String
184
+ config[:log] = File.open(log, 'a')
185
+ when File
186
+ log = log.path
187
+ when IO
188
+ abort "Invalid log file: #{log.tty? ? "FILENO=#{log.fileno}" : log}"
189
+ else
190
+ abort 'Log file missing!'
191
+ end
192
+
193
+ if File.readable?(log)
194
+ require 'elif'
195
+
196
+ pid = nil
197
+
198
+ Elif.foreach(log) { |line|
199
+ case line
200
+ when /\A(\d+)\z/
201
+ pid ||= $1.to_i
202
+ break if options[:last]
203
+ when / TWITTER (\d+)\z/
204
+ options[:last] ||= $1.to_i
205
+ break if pid
206
+ end
207
+ }
208
+
209
+ begin
210
+ Process.kill(:INT, pid)
211
+ sleep 1
212
+ rescue Errno::ESRCH
213
+ end if pid
214
+ end
215
+ end
216
+
169
217
  twitter2jabber = Twitter2Jabber.new(config)
170
218
 
171
219
  if options[:loop]
172
- warn Process.pid if options[:verbose]
220
+ twitter2jabber.send(:log_, Process.pid)
173
221
  twitter2jabber.loop(recipients, options[:pause] || config[:pause], options[:last])
174
222
  else
175
223
  twitter2jabber.run(recipients, options[:last])
@@ -4,7 +4,7 @@ class Twitter2Jabber
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 8
7
+ TINY = 9
8
8
 
9
9
  class << self
10
10
 
@@ -56,7 +56,7 @@ class Twitter2Jabber
56
56
  new(options).run(recipients, last, &block)
57
57
  end
58
58
 
59
- attr_reader :id, :verbose, :debug, :twitter, :jabber, :filter, :formats, :templates, :_erb
59
+ attr_reader :id, :verbose, :debug, :log, :twitter, :jabber, :filter, :formats, :templates, :_erb
60
60
 
61
61
  def initialize(options, &block)
62
62
  [:twitter, :jabber].each { |client|
@@ -67,8 +67,9 @@ class Twitter2Jabber
67
67
 
68
68
  @verbose = options[:verbose]
69
69
  @debug = options[:debug]
70
+ @log = options[:log]
70
71
 
71
- log 'HAI!'
72
+ logm 'HAI!'
72
73
 
73
74
  @twitter = twitter_connect(options[:twitter])
74
75
  @jabber = jabber_connect(options[:jabber])
@@ -101,7 +102,7 @@ class Twitter2Jabber
101
102
  i = 1
102
103
 
103
104
  trap(:INT) {
104
- log 'SIGINT received, shutting down...'
105
+ logm 'SIGINT received, shutting down...'
105
106
  i = -1
106
107
  }
107
108
 
@@ -113,7 +114,7 @@ class Twitter2Jabber
113
114
  i += 1
114
115
  end
115
116
 
116
- log 'KTHXBYE!'
117
+ logm 'KTHXBYE!'
117
118
 
118
119
  last
119
120
  end
@@ -350,16 +351,20 @@ le[n[gth]] STATUS -- Determine length
350
351
  twitter.update(msg, options)
351
352
  end
352
353
 
353
- def log(msg, verbose = verbose)
354
- warn "#{Time.now} [#{id}] #{msg}" if verbose
354
+ def log_(msg, verbose = verbose)
355
+ log.puts msg if verbose
356
+ end
357
+
358
+ def logm(msg, verbose = verbose)
359
+ log_("#{Time.now} [#{id}] #{msg}", verbose)
355
360
  end
356
361
 
357
362
  def logt(msg, verbose = verbose)
358
- log("TWITTER #{msg}", verbose)
363
+ logm("TWITTER #{msg}", verbose)
359
364
  end
360
365
 
361
366
  def logj(msg, verbose = verbose)
362
- log("JABBER #{msg}", verbose)
367
+ logm("JABBER #{msg}", verbose)
363
368
  end
364
369
 
365
370
  end
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -62,6 +62,16 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: "0"
64
64
  version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: elif
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
65
75
  description: Twitter-to-Jabber gateway.
66
76
  email: jens.wille@uni-koeln.de
67
77
  executables: