rjp-twittermoo 0.0.4 → 0.0.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.
Files changed (2) hide show
  1. data/bin/twittermoo.rb +38 -17
  2. metadata +3 -3
data/bin/twittermoo.rb CHANGED
@@ -1,3 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
1
3
  require 'rubygems'
2
4
  require 'twitter'
3
5
  require 'gdbm'
@@ -5,6 +7,13 @@ require 'sha1'
5
7
  require 'optparse'
6
8
  require 'socket'
7
9
 
10
+ # TODO move this to something like log4r if they have it
11
+ def log(x)
12
+ if $options[:verbose] then
13
+ puts *x
14
+ end
15
+ end
16
+
8
17
  $options = {
9
18
  :host => 'localhost',
10
19
  :port => nil,
@@ -64,33 +73,45 @@ OptionParser.new do |opts|
64
73
  end.parse!
65
74
 
66
75
  if $options[:keyfile] then
67
- puts "loading secret key from #{$options[:keyfile]}"
68
- $options[:secret_key] = File.open($options[:keyfile]).read.chomp
76
+ log "loading secret key from #{$options[:keyfile]}"
77
+ begin
78
+ $options[:secret_key] = File.open($options[:keyfile]).read.chomp
79
+ rescue => e
80
+ $stderr.puts "Error getting secret key from #{$options[:keyfile]}: #{e}"
81
+ exit(1)
82
+ end
69
83
  end
70
84
 
71
85
  def send_message(x)
72
86
  if $options[:port].nil? then
73
87
  puts "! #{x}"
74
88
  else
75
- begin
76
- # irc_cat doesn't seem to like persistent connections
77
- $socket = TCPSocket.new($options[:host], $options[:port])
78
- if $options[:secret_key] then
79
- x = "%/#{$options[:secret_key]}/% #{x}"
80
- end
81
- $socket.puts(x)
82
- $socket.close
89
+ attempts = 5
90
+ loop do
91
+ begin
92
+ # irc_cat doesn't seem to like persistent connections
93
+ $socket = TCPSocket.new($options[:host], $options[:port])
94
+ if $options[:secret_key] then
95
+ x = "%/#{$options[:secret_key]}/% #{x}"
96
+ end
97
+ $socket.puts(x)
98
+ $socket.close
99
+ rescue
100
+ log "E $!"
101
+ attempts = attempts - 1
102
+ if attempts == 0 then
103
+ log "too many failures, bailing for 120s"
104
+ sleep 120
105
+ attempts = 5
106
+ else
107
+ log "transient failure, sleeping for 30s"
108
+ sleep 30
109
+ end
110
+ end
83
111
  end
84
112
  end
85
113
  end
86
114
 
87
- # TODO move this to something like log4r if they have it
88
- def log(x)
89
- if $options[:verbose] then
90
- puts *x
91
- end
92
- end
93
-
94
115
  config = YAML::load(open($options[:config]))
95
116
 
96
117
  # allow settings of options from the config file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjp-twittermoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Partington
@@ -24,8 +24,8 @@ dependencies:
24
24
  version:
25
25
  description:
26
26
  email: zimpenfish@gmail.com
27
- executables: []
28
-
27
+ executables:
28
+ - twittermoo.rb
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files: []