balinterdi-cuckoo_twitterer 0.1
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 +1 -0
- data/Manifest +13 -0
- data/Rakefile +15 -0
- data/bin/cuckoo_twitterer.rb +12 -0
- data/config/bot.yml +2 -0
- data/cuckoo_twitterer.gemspec +32 -0
- data/lib/cuckoo_twitterer.rb +37 -0
- data/lib/environments.rb +8 -0
- data/lib/modules/one_line_from_file.rb +76 -0
- data/spec/cuckoo_twitterer_spec.rb +35 -0
- data/spec/one_line_from_file_spec.rb +108 -0
- data/spec/spec.opts +5 -0
- data/tasks/spec.rake +11 -0
- metadata +73 -0
data/CHANGELOG
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v0.1 Initial release: can tweet from a file.
|
data/Manifest
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
bin/cuckoo_twitterer.rb
|
|
2
|
+
CHANGELOG
|
|
3
|
+
config/bot.yml
|
|
4
|
+
cuckoo_twitterer.gemspec
|
|
5
|
+
lib/cuckoo_twitterer.rb
|
|
6
|
+
lib/environments.rb
|
|
7
|
+
lib/modules/one_line_from_file.rb
|
|
8
|
+
Manifest
|
|
9
|
+
Rakefile
|
|
10
|
+
spec/cuckoo_twitterer_spec.rb
|
|
11
|
+
spec/one_line_from_file_spec.rb
|
|
12
|
+
spec/spec.opts
|
|
13
|
+
tasks/spec.rake
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'echoe'
|
|
4
|
+
|
|
5
|
+
Echoe.new('cuckoo_twitterer', '0.1') do |p|
|
|
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
|
+
p.url = "http://github.com/balinterdi/cuckoo_twitterer"
|
|
8
|
+
p.author = "Bálint Érdi"
|
|
9
|
+
p.email = "balint.erdi@bucionrails.com"
|
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*", "*.txt"]
|
|
11
|
+
p.development_dependencies = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
|
15
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
|
+
|
|
3
|
+
require File.join(dir, 'cuckoo_twitterer')
|
|
4
|
+
|
|
5
|
+
Dir.glob(File.join(dir, 'modules', '*.rb')).each do |mod|
|
|
6
|
+
require mod
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
CuckooTwitterer.send(:include, OneLineFromFile)
|
|
10
|
+
@cuckoo = CuckooTwitterer.new
|
|
11
|
+
# @cuckoo.set_testing
|
|
12
|
+
@cuckoo.run
|
data/config/bot.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{cuckoo_twitterer}
|
|
5
|
+
s.version = "0.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["B\303\241lint \303\211rdi"]
|
|
9
|
+
s.date = %q{2009-06-09}
|
|
10
|
+
s.default_executable = %q{cuckoo_twitterer.rb}
|
|
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
|
+
s.email = %q{balint.erdi@bucionrails.com}
|
|
13
|
+
s.executables = ["cuckoo_twitterer.rb"]
|
|
14
|
+
s.extra_rdoc_files = ["bin/cuckoo_twitterer.rb", "CHANGELOG", "lib/cuckoo_twitterer.rb", "lib/environments.rb", "lib/modules/one_line_from_file.rb", "tasks/spec.rake"]
|
|
15
|
+
s.files = ["bin/cuckoo_twitterer.rb", "CHANGELOG", "config/bot.yml", "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"]
|
|
16
|
+
s.homepage = %q{http://github.com/balinterdi/cuckoo_twitterer}
|
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cuckoo_twitterer"]
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
s.rubyforge_project = %q{cuckoo_twitterer}
|
|
20
|
+
s.rubygems_version = %q{1.3.3}
|
|
21
|
+
s.summary = %q{A simple yet elegant solution to tweet a message regularly from a file (and in the future: from a webpage, a database, etc.)}
|
|
22
|
+
|
|
23
|
+
if s.respond_to? :specification_version then
|
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
25
|
+
s.specification_version = 3
|
|
26
|
+
|
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
28
|
+
else
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'environments')
|
|
2
|
+
require 'twibot'
|
|
3
|
+
require "ruby-debug"
|
|
4
|
+
|
|
5
|
+
class CuckooTwitterer
|
|
6
|
+
include CuckooEnvironment
|
|
7
|
+
# the idea is to include a module with a well-defined API with three methods:
|
|
8
|
+
# - load_tweets
|
|
9
|
+
# - next
|
|
10
|
+
# - store(tweet)
|
|
11
|
+
def tweet
|
|
12
|
+
next_tweet = self.next
|
|
13
|
+
unless next_tweet.nil?
|
|
14
|
+
store(next_tweet)
|
|
15
|
+
if testing?
|
|
16
|
+
puts "Tweeting #{next_tweet}"
|
|
17
|
+
else
|
|
18
|
+
twitter.status(:post, next_tweet)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
next_tweet
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run
|
|
25
|
+
load_tweets
|
|
26
|
+
loop do
|
|
27
|
+
tweeted = tweet
|
|
28
|
+
quit if tweeted.nil?
|
|
29
|
+
sleep(24*24*60)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def quit
|
|
34
|
+
exit
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
data/lib/environments.rb
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# require 'scrubyt'
|
|
2
|
+
require "rubygems"
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
require "hpricot"
|
|
5
|
+
|
|
6
|
+
module OneLineFromFile
|
|
7
|
+
# read all lines from the file that contains the strategies
|
|
8
|
+
# select the strategies that are not used yet
|
|
9
|
+
# pick a random strategy
|
|
10
|
+
|
|
11
|
+
# store used strategies in a file with (store the md5 sum of the strategies' text)
|
|
12
|
+
attr_reader :lines
|
|
13
|
+
|
|
14
|
+
LINES_FILE = 'lines.txt'
|
|
15
|
+
USED_LINES_FILE = 'used_lines.txt'
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
@lines = []
|
|
19
|
+
# load_lines
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def load_tweets
|
|
23
|
+
load_lines
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_lines_from_file
|
|
27
|
+
begin
|
|
28
|
+
IO::readlines(LINES_FILE).map { |line| line.chomp }
|
|
29
|
+
rescue Errno::ENOENT
|
|
30
|
+
[]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_all_lines
|
|
35
|
+
@fresh_lines ||= get_lines_from_file
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_used_lines_from_file
|
|
39
|
+
begin
|
|
40
|
+
IO::readlines(USED_LINES_FILE).map { |line| line.chomp }
|
|
41
|
+
rescue Errno::ENOENT
|
|
42
|
+
[]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_used_lines
|
|
47
|
+
@used_lines ||= get_used_lines_from_file
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def load_lines
|
|
51
|
+
# debugger
|
|
52
|
+
used = get_used_lines
|
|
53
|
+
unused_lines = get_all_lines.select { |line| !used.include?(line) }
|
|
54
|
+
add_lines(*unused_lines)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def add_lines(*new_lines)
|
|
58
|
+
@lines.concat(new_lines)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def pick
|
|
62
|
+
rand(lines.length)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def store(line)
|
|
66
|
+
open(USED_LINES_FILE, "a") do |file|
|
|
67
|
+
file.write(line + "\n")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def next
|
|
72
|
+
@lines.delete_at(pick)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "spec"
|
|
2
|
+
dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
|
+
require File.join(dir, 'cuckoo_twitterer')
|
|
4
|
+
require File.join(dir, 'environments')
|
|
5
|
+
|
|
6
|
+
class CuckooTwittererSpec
|
|
7
|
+
extend CuckooEnvironment
|
|
8
|
+
set_testing
|
|
9
|
+
|
|
10
|
+
describe "A cuckoo twitterer" do
|
|
11
|
+
before do
|
|
12
|
+
@cuckoo = CuckooTwitterer.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "responds to tweet" do
|
|
16
|
+
@cuckoo.should respond_to(:tweet)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "when there is nothing to tweet" do
|
|
20
|
+
before do
|
|
21
|
+
@cuckoo.stubs(:next).returns(nil)
|
|
22
|
+
@cuckoo.stubs(:load_tweets).returns(nil)
|
|
23
|
+
end
|
|
24
|
+
it "does not call store" do
|
|
25
|
+
@cuckoo.expects(:store).never
|
|
26
|
+
@cuckoo.tweet
|
|
27
|
+
end
|
|
28
|
+
it "quits" do
|
|
29
|
+
pending
|
|
30
|
+
@cuckoo.expects(:quit).once
|
|
31
|
+
@cuckoo.run
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require "spec"
|
|
2
|
+
require "mocha"
|
|
3
|
+
|
|
4
|
+
dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
+
require File.join(dir, 'cuckoo_twitterer')
|
|
6
|
+
require File.join(dir, 'modules', 'one_line_from_file')
|
|
7
|
+
require File.join(dir, 'environments')
|
|
8
|
+
|
|
9
|
+
# use mocha for mocking instead of
|
|
10
|
+
# Rspec's own mock framework
|
|
11
|
+
Spec::Runner.configure do |config|
|
|
12
|
+
config.mock_with :mocha
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class CuckooTwittererWithOneLineFromFileSpec
|
|
16
|
+
|
|
17
|
+
extend CuckooEnvironment
|
|
18
|
+
set_testing
|
|
19
|
+
|
|
20
|
+
describe "A cuckoo twitterer with one line from a file" do
|
|
21
|
+
before do
|
|
22
|
+
CuckooTwitterer.send(:include, OneLineFromFile)
|
|
23
|
+
@cuckoo = CuckooTwitterer.new
|
|
24
|
+
# just so that no files will be written
|
|
25
|
+
@cuckoo.stubs(:store).returns(nil)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "stores a line that was sent to it correctly" do
|
|
29
|
+
@cuckoo.lines.should be_empty
|
|
30
|
+
@cuckoo.add_lines("I am happy", "I am sad")
|
|
31
|
+
@cuckoo.lines.should == ["I am happy", "I am sad"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "loads all the lines in the file when sent the load_tweets message" do
|
|
35
|
+
lines = ["I am happy", "I am sad", "I am thrilled", "I am bored"]
|
|
36
|
+
@cuckoo.expects(:get_lines_from_file).returns(lines)
|
|
37
|
+
@cuckoo.load_tweets
|
|
38
|
+
@cuckoo.lines.should == lines
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "when it tweeted a line already" do
|
|
42
|
+
before do
|
|
43
|
+
@cuckoo.add_lines("I am happy", "I am sad", "I am thrilled", "I am bored")
|
|
44
|
+
@cuckoo.stubs(:pick).returns(0)
|
|
45
|
+
@cuckoo.tweet
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "it removes it" do
|
|
49
|
+
@cuckoo.lines.should == ["I am sad", "I am thrilled", "I am bored"]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "stores it" do
|
|
53
|
+
@cuckoo.stubs(:pick).returns(0)
|
|
54
|
+
@cuckoo.expects(:store).with("I am sad")
|
|
55
|
+
@cuckoo.tweet
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "it picks an unused line to tweet next" do
|
|
59
|
+
next_pick = @cuckoo.next
|
|
60
|
+
["I am sad", "I am thrilled", "I am bored"].should include(next_pick)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "tweets all the available lines in as many 'rounds' as there are lines" do
|
|
65
|
+
lines = ["I am happy", "I am sad", "I am thrilled", "I am bored"]
|
|
66
|
+
@cuckoo.add_lines(*lines)
|
|
67
|
+
lines.length.times { @cuckoo.tweet }
|
|
68
|
+
@cuckoo.lines.should be_empty
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "only reads the file to load lines from the first time around" do
|
|
72
|
+
pending
|
|
73
|
+
@cuckoo.stubs(:get_used_lines_from_file).returns([])
|
|
74
|
+
@cuckoo.expects(:get_lines_from_file).returns(["I am happy", "I am sad", "I am thrilled", "I am bored"])
|
|
75
|
+
2.times { @cuckoo.load_lines }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "only reads the file to load used lines from the first time around" do
|
|
79
|
+
pending
|
|
80
|
+
@cuckoo.stubs(:get_lines_from_file).returns(["I am happy", "I am sad", "I am thrilled", "I am bored"])
|
|
81
|
+
@cuckoo.expects(:get_used_lines_from_file).returns([])
|
|
82
|
+
2.times { @cuckoo.load_lines }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "when loading lines to use" do
|
|
86
|
+
before do
|
|
87
|
+
@cuckoo.stubs(:get_lines_from_file).returns(["I am happy", "I am sad", "I am thrilled", "I am bored"])
|
|
88
|
+
@cuckoo.stubs(:get_used_lines_from_file).returns([])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "loads the available ones" do
|
|
92
|
+
@cuckoo.load_lines
|
|
93
|
+
@cuckoo.lines.should == ["I am happy", "I am sad", "I am thrilled", "I am bored"]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "when having used ones from a previous run" do
|
|
97
|
+
before do
|
|
98
|
+
@cuckoo.stubs(:get_used_lines_from_file).returns(["I am happy", "I am sad"])
|
|
99
|
+
@cuckoo.load_lines
|
|
100
|
+
end
|
|
101
|
+
it "should not pick those used lines" do
|
|
102
|
+
@cuckoo.lines.should == ["I am thrilled", "I am bored"]
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
data/spec/spec.opts
ADDED
data/tasks/spec.rake
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "rake"
|
|
3
|
+
require "spec/rake/spectask"
|
|
4
|
+
|
|
5
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
6
|
+
|
|
7
|
+
desc "Run all specs"
|
|
8
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
|
9
|
+
t.spec_opts << '--options' << ROOT + '/spec/spec.opts'
|
|
10
|
+
t.spec_files = Dir.glob('spec/**/*_spec.rb').map { |f| f.to_s }
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: balinterdi-cuckoo_twitterer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "0.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "B\xC3\xA1lint \xC3\x89rdi"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-06-09 00:00:00 -07:00
|
|
13
|
+
default_executable: cuckoo_twitterer.rb
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: "A simple yet elegant solution to tweet a message regularly from a file (and in the future: from a webpage, a database, etc.)"
|
|
17
|
+
email: balint.erdi@bucionrails.com
|
|
18
|
+
executables:
|
|
19
|
+
- cuckoo_twitterer.rb
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- bin/cuckoo_twitterer.rb
|
|
24
|
+
- CHANGELOG
|
|
25
|
+
- lib/cuckoo_twitterer.rb
|
|
26
|
+
- lib/environments.rb
|
|
27
|
+
- lib/modules/one_line_from_file.rb
|
|
28
|
+
- tasks/spec.rake
|
|
29
|
+
files:
|
|
30
|
+
- bin/cuckoo_twitterer.rb
|
|
31
|
+
- CHANGELOG
|
|
32
|
+
- config/bot.yml
|
|
33
|
+
- cuckoo_twitterer.gemspec
|
|
34
|
+
- lib/cuckoo_twitterer.rb
|
|
35
|
+
- lib/environments.rb
|
|
36
|
+
- lib/modules/one_line_from_file.rb
|
|
37
|
+
- Manifest
|
|
38
|
+
- Rakefile
|
|
39
|
+
- spec/cuckoo_twitterer_spec.rb
|
|
40
|
+
- spec/one_line_from_file_spec.rb
|
|
41
|
+
- spec/spec.opts
|
|
42
|
+
- tasks/spec.rake
|
|
43
|
+
has_rdoc: false
|
|
44
|
+
homepage: http://github.com/balinterdi/cuckoo_twitterer
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options:
|
|
47
|
+
- --line-numbers
|
|
48
|
+
- --inline-source
|
|
49
|
+
- --title
|
|
50
|
+
- Cuckoo_twitterer
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
version:
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: "1.2"
|
|
64
|
+
version:
|
|
65
|
+
requirements: []
|
|
66
|
+
|
|
67
|
+
rubyforge_project: cuckoo_twitterer
|
|
68
|
+
rubygems_version: 1.2.0
|
|
69
|
+
signing_key:
|
|
70
|
+
specification_version: 3
|
|
71
|
+
summary: "A simple yet elegant solution to tweet a message regularly from a file (and in the future: from a webpage, a database, etc.)"
|
|
72
|
+
test_files: []
|
|
73
|
+
|