rjp-twittermoo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/twittermoo.rb +21 -6
- metadata +1 -1
data/bin/twittermoo.rb
CHANGED
@@ -12,11 +12,13 @@ $options = {
|
|
12
12
|
:config => ENV['HOME'] + '/.twittermoo',
|
13
13
|
:verbose => nil,
|
14
14
|
:once => nil,
|
15
|
-
:wait => 20
|
15
|
+
:wait => 20,
|
16
|
+
:period => 3600,
|
17
|
+
:every => 300
|
16
18
|
}
|
17
19
|
|
18
20
|
OptionParser.new do |opts|
|
19
|
-
opts.banner = "Usage: twittermoo.rb [-v] [-p port] [-h host] [-d dbfile] [-c config] [-o] [-w N]"
|
21
|
+
opts.banner = "Usage: twittermoo.rb [-v] [-p port] [-h host] [-d dbfile] [-c config] [-o] [-w N] [-p N] [-e N]"
|
20
22
|
|
21
23
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
22
24
|
$options[:verbose] = v
|
@@ -26,10 +28,18 @@ OptionParser.new do |opts|
|
|
26
28
|
$options[:once] = p
|
27
29
|
end
|
28
30
|
|
29
|
-
opts.on("-w", "--wait N", Integer, "Delay between sending messages") do |p|
|
31
|
+
opts.on("-w", "--wait N", Integer, "Delay between sending messages (seconds)") do |p|
|
30
32
|
$options[:wait] = p
|
31
33
|
end
|
32
34
|
|
35
|
+
opts.on("-p", "--period N", Integer, "Time period to check for new messages (seconds)") do |p|
|
36
|
+
$options[:period] = p
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-e", "--every N", Integer, "Time period to sleep between checks (seconds, 300+)") do |p|
|
40
|
+
$options[:every] = p
|
41
|
+
end
|
42
|
+
|
33
43
|
opts.on("-p", "--port N", Integer, "irccat port") do |p|
|
34
44
|
$options[:port] = p
|
35
45
|
end
|
@@ -69,6 +79,11 @@ end
|
|
69
79
|
|
70
80
|
config = YAML::load(open($options[:config]))
|
71
81
|
|
82
|
+
# allow settings of options from the config file
|
83
|
+
unless config['options'].nil? then
|
84
|
+
options.merge!(config['options'])
|
85
|
+
}
|
86
|
+
|
72
87
|
# TODO add an option for OAuth
|
73
88
|
httpauth = Twitter::HTTPAuth.new(config['email'], config['password'])
|
74
89
|
twitter = Twitter::Base.new(httpauth)
|
@@ -80,14 +95,14 @@ if $options[:once].nil? then
|
|
80
95
|
twitter.friends_timeline().each do |s|
|
81
96
|
sha1 = SHA1.hexdigest(s.text + s.user.name)
|
82
97
|
xtime = Time.parse(s.created_at)
|
83
|
-
threshold = Time.now -
|
98
|
+
threshold = Time.now - $options[:period]
|
84
99
|
if xtime < threshold then
|
85
100
|
already_seen[sha1] = "s"
|
86
101
|
end
|
87
102
|
end
|
88
103
|
end
|
89
104
|
|
90
|
-
prev_time = Time.now -
|
105
|
+
prev_time = Time.now - $options[:period]
|
91
106
|
log "L entering main loop"
|
92
107
|
loop {
|
93
108
|
|
@@ -167,7 +182,7 @@ loop {
|
|
167
182
|
|
168
183
|
if $options[:once].nil? then
|
169
184
|
log "S #{Time.now}"
|
170
|
-
sleep
|
185
|
+
sleep $options[:every]
|
171
186
|
else
|
172
187
|
break
|
173
188
|
end
|