balinterdi-cuckoo_twitterer 0.1.1 → 0.1.3
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/CHANGELOG +4 -1
- data/Manifest +2 -0
- data/Rakefile +1 -1
- data/bin/cuckoo_twitterer +1 -1
- data/cuckoo_twitterer.gemspec +4 -4
- data/lib/cuckoo_twitterer.rb +30 -3
- data/lib/duration_string.rb +12 -0
- data/lib/modules/one_line_from_file.rb +0 -1
- data/spec/cuckoo_twitterer_spec.rb +17 -5
- data/spec/duration_string_spec.rb +30 -0
- metadata +5 -2
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
|
@@ -2,11 +2,13 @@ bin/cuckoo_twitterer
|
|
|
2
2
|
CHANGELOG
|
|
3
3
|
cuckoo_twitterer.gemspec
|
|
4
4
|
lib/cuckoo_twitterer.rb
|
|
5
|
+
lib/duration_string.rb
|
|
5
6
|
lib/environments.rb
|
|
6
7
|
lib/modules/one_line_from_file.rb
|
|
7
8
|
Manifest
|
|
8
9
|
Rakefile
|
|
9
10
|
spec/cuckoo_twitterer_spec.rb
|
|
11
|
+
spec/duration_string_spec.rb
|
|
10
12
|
spec/one_line_from_file_spec.rb
|
|
11
13
|
spec/spec.opts
|
|
12
14
|
tasks/spec.rake
|
data/Rakefile
CHANGED
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
require 'rake'
|
|
3
3
|
require 'echoe'
|
|
4
4
|
|
|
5
|
-
Echoe.new('cuckoo_twitterer', '0.1.
|
|
5
|
+
Echoe.new('cuckoo_twitterer', '0.1.3') do |p|
|
|
6
6
|
p.description = "A simple yet elegant solution to tweet a message regularly from a file (and in the future: from a webpage, a database, etc.)"
|
|
7
7
|
p.url = "http://github.com/balinterdi/cuckoo_twitterer"
|
|
8
8
|
p.author = "Bálint Érdi"
|
data/bin/cuckoo_twitterer
CHANGED
data/cuckoo_twitterer.gemspec
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{cuckoo_twitterer}
|
|
5
|
-
s.version = "0.1.
|
|
5
|
+
s.version = "0.1.3"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["B\303\241lint \303\211rdi"]
|
|
9
|
-
s.date = %q{2009-06-
|
|
9
|
+
s.date = %q{2009-06-12}
|
|
10
10
|
s.default_executable = %q{cuckoo_twitterer}
|
|
11
11
|
s.description = %q{A simple yet elegant solution to tweet a message regularly from a file (and in the future: from a webpage, a database, etc.)}
|
|
12
12
|
s.email = %q{balint.erdi@bucionrails.com}
|
|
13
13
|
s.executables = ["cuckoo_twitterer"]
|
|
14
|
-
s.extra_rdoc_files = ["bin/cuckoo_twitterer", "CHANGELOG", "lib/cuckoo_twitterer.rb", "lib/environments.rb", "lib/modules/one_line_from_file.rb", "tasks/spec.rake"]
|
|
15
|
-
s.files = ["bin/cuckoo_twitterer", "CHANGELOG", "cuckoo_twitterer.gemspec", "lib/cuckoo_twitterer.rb", "lib/environments.rb", "lib/modules/one_line_from_file.rb", "Manifest", "Rakefile", "spec/cuckoo_twitterer_spec.rb", "spec/one_line_from_file_spec.rb", "spec/spec.opts", "tasks/spec.rake"]
|
|
14
|
+
s.extra_rdoc_files = ["bin/cuckoo_twitterer", "CHANGELOG", "lib/cuckoo_twitterer.rb", "lib/duration_string.rb", "lib/environments.rb", "lib/modules/one_line_from_file.rb", "tasks/spec.rake"]
|
|
15
|
+
s.files = ["bin/cuckoo_twitterer", "CHANGELOG", "cuckoo_twitterer.gemspec", "lib/cuckoo_twitterer.rb", "lib/duration_string.rb", "lib/environments.rb", "lib/modules/one_line_from_file.rb", "Manifest", "Rakefile", "spec/cuckoo_twitterer_spec.rb", "spec/duration_string_spec.rb", "spec/one_line_from_file_spec.rb", "spec/spec.opts", "tasks/spec.rake"]
|
|
16
16
|
s.homepage = %q{http://github.com/balinterdi/cuckoo_twitterer}
|
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cuckoo_twitterer"]
|
|
18
18
|
s.require_paths = ["lib"]
|
data/lib/cuckoo_twitterer.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'environments')
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'duration_string')
|
|
3
4
|
require 'twibot'
|
|
4
5
|
|
|
5
6
|
class CuckooTwitterer
|
|
@@ -8,12 +9,19 @@ class CuckooTwitterer
|
|
|
8
9
|
# - load_tweets
|
|
9
10
|
# - next
|
|
10
11
|
# - store(tweet)
|
|
12
|
+
attr_accessor :time_to_sleep
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@time_to_sleep = "1d"
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
11
19
|
def tweet
|
|
12
20
|
next_tweet = self.next
|
|
13
21
|
unless next_tweet.nil?
|
|
14
22
|
store(next_tweet)
|
|
15
23
|
if testing?
|
|
16
|
-
puts "Tweeting #{next_tweet}"
|
|
24
|
+
puts "(test) Tweeting #{next_tweet}"
|
|
17
25
|
else
|
|
18
26
|
twitter.status(:post, next_tweet)
|
|
19
27
|
end
|
|
@@ -21,12 +29,32 @@ class CuckooTwitterer
|
|
|
21
29
|
next_tweet
|
|
22
30
|
end
|
|
23
31
|
|
|
32
|
+
def get_config_values_from_file
|
|
33
|
+
config_values = {}
|
|
34
|
+
open('config/cuckoo.yml', 'r') do |f|
|
|
35
|
+
config_values = YAML.load(f.read)
|
|
36
|
+
end
|
|
37
|
+
config_values
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def setup
|
|
41
|
+
get_config_values_from_file.each_pair do |attr, value|
|
|
42
|
+
self.send("#{attr}=".to_sym, value)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def relax
|
|
47
|
+
seconds_to_sleep = DurationString.to_seconds(time_to_sleep)
|
|
48
|
+
sleep(seconds_to_sleep)
|
|
49
|
+
end
|
|
50
|
+
|
|
24
51
|
def run
|
|
52
|
+
setup
|
|
25
53
|
load_tweets
|
|
26
54
|
loop do
|
|
27
55
|
tweeted = tweet
|
|
28
56
|
quit if tweeted.nil?
|
|
29
|
-
|
|
57
|
+
relax
|
|
30
58
|
end
|
|
31
59
|
end
|
|
32
60
|
|
|
@@ -34,4 +62,3 @@ class CuckooTwitterer
|
|
|
34
62
|
exit
|
|
35
63
|
end
|
|
36
64
|
end
|
|
37
|
-
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module DurationString
|
|
2
|
+
class << self
|
|
3
|
+
MULTIPLIERS = { "s" => 1, "m" => 60, "h" => 60 * 60, "d" => 60 * 60 * 24, "w" => 60 * 60 * 24 * 7 }
|
|
4
|
+
def to_seconds(duration)
|
|
5
|
+
duration.scan(/(\d+)([smhdw])/).inject(0) do |seconds, match|
|
|
6
|
+
num, dur_chr = match
|
|
7
|
+
multiplier = MULTIPLIERS[dur_chr]
|
|
8
|
+
seconds + num.to_i * multiplier
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -6,19 +6,31 @@ require File.join(dir, 'environments')
|
|
|
6
6
|
class CuckooTwittererSpec
|
|
7
7
|
extend CuckooEnvironment
|
|
8
8
|
set_testing
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
describe "A cuckoo twitterer" do
|
|
11
11
|
before do
|
|
12
12
|
@cuckoo = CuckooTwitterer.new
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
it "responds to tweet" do
|
|
16
16
|
@cuckoo.should respond_to(:tweet)
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
it "waits 1 day between tweets by default" do
|
|
20
|
+
@cuckoo.time_to_sleep.should == "1d"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "loading values from the config file" do
|
|
24
|
+
it "sets the time interval to wait b/w tweets correctly" do
|
|
25
|
+
@cuckoo.expects(:get_config_values_from_file).returns({ :time_to_sleep => "3m" })
|
|
26
|
+
@cuckoo.setup
|
|
27
|
+
@cuckoo.time_to_sleep.should == "3m"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
19
31
|
describe "when there is nothing to tweet" do
|
|
20
32
|
before do
|
|
21
|
-
@cuckoo.stubs(:next).returns(nil)
|
|
33
|
+
@cuckoo.stubs(:next).returns(nil)
|
|
22
34
|
@cuckoo.stubs(:load_tweets).returns(nil)
|
|
23
35
|
end
|
|
24
36
|
it "does not call store" do
|
|
@@ -29,7 +41,7 @@ class CuckooTwittererSpec
|
|
|
29
41
|
pending
|
|
30
42
|
@cuckoo.expects(:quit).once
|
|
31
43
|
@cuckoo.run
|
|
32
|
-
end
|
|
44
|
+
end
|
|
33
45
|
end
|
|
34
46
|
end
|
|
35
47
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "spec"
|
|
2
|
+
dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
|
+
require File.join(dir, 'duration_string')
|
|
4
|
+
|
|
5
|
+
describe "a string representing a duration" do
|
|
6
|
+
it "gives back the number of seconds for seconds" do
|
|
7
|
+
DurationString.to_seconds("17s").should == 17
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "gives back the number of seconds for dur. strings with only minutes defined" do
|
|
11
|
+
DurationString.to_seconds("7m").should == 7 * 60
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "gives back the number of seconds for hours for dur. strings with only hours defined" do
|
|
15
|
+
DurationString.to_seconds("4h").should == 60 * 60 * 4
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "gives back the number of seconds for hours for dur. strings with only days defined" do
|
|
19
|
+
DurationString.to_seconds("2d").should == 60 * 60 * 24 * 2
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "gives back the number of seconds for hours for dur. strings with only weeks defined" do
|
|
23
|
+
DurationString.to_seconds("3w").should == 60 * 60 * 24 * 7 * 3
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "gives back the number of seconds for a dur. string that combines several dur. characters" do
|
|
27
|
+
DurationString.to_seconds("1d3h18m22s").should == (60 * 60 * 24 * 1) + (60 * 60 * 3) + (60 * 18) + 22
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: balinterdi-cuckoo_twitterer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "B\xC3\xA1lint \xC3\x89rdi"
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-06-
|
|
12
|
+
date: 2009-06-12 00:00:00 -07:00
|
|
13
13
|
default_executable: cuckoo_twitterer
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -23,6 +23,7 @@ extra_rdoc_files:
|
|
|
23
23
|
- bin/cuckoo_twitterer
|
|
24
24
|
- CHANGELOG
|
|
25
25
|
- lib/cuckoo_twitterer.rb
|
|
26
|
+
- lib/duration_string.rb
|
|
26
27
|
- lib/environments.rb
|
|
27
28
|
- lib/modules/one_line_from_file.rb
|
|
28
29
|
- tasks/spec.rake
|
|
@@ -31,11 +32,13 @@ files:
|
|
|
31
32
|
- CHANGELOG
|
|
32
33
|
- cuckoo_twitterer.gemspec
|
|
33
34
|
- lib/cuckoo_twitterer.rb
|
|
35
|
+
- lib/duration_string.rb
|
|
34
36
|
- lib/environments.rb
|
|
35
37
|
- lib/modules/one_line_from_file.rb
|
|
36
38
|
- Manifest
|
|
37
39
|
- Rakefile
|
|
38
40
|
- spec/cuckoo_twitterer_spec.rb
|
|
41
|
+
- spec/duration_string_spec.rb
|
|
39
42
|
- spec/one_line_from_file_spec.rb
|
|
40
43
|
- spec/spec.opts
|
|
41
44
|
- tasks/spec.rake
|