twuckoo 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -69,7 +69,7 @@ By default, it is "1d", so the script will "relax" for 24 hours after tweeting.
69
69
  * password
70
70
  * email
71
71
 
72
- When twuckoo is out of messages to tweet, it quits. Most of the times you'll want to get notified of this, though, so you can take action (e.g refill it and relaunch). If the above options are set, twuckoo sends an email to `email`, using the `user` and `password` credentials for gmail authentication. (Yes, currently only gmail is supported, I'll change that shortly.)
72
+ When twuckoo is out of messages to tweet, it quits. Most of the times you'll want to get notified of this, though, so you can take action (e.g refill it and relaunch). If the above options are set, twuckoo sends an email to `email`, using the `user` and `password` credentials for gmail authentication. (Yes, currently only gmail is supported, I am planning to change that in a next version.)
73
73
 
74
74
  ## Running
75
75
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  gemspec.name = "twuckoo"
7
7
  gemspec.summary = "Need to tweet periodically in an automated fashion? Then Twuckoo is for you!"
8
8
  gemspec.description = <<-EOF
9
- A simple yet elegant solution to tweet a message regularly from a file (from a webpage, a database, etc.)
9
+ A simple yet elegant solution to tweet a message regularly from a file (or from a webpage, a database, etc.)
10
10
  EOF
11
11
  gemspec.email = "balint.erdi@gmail.com"
12
12
  gemspec.homepage = "http://github.com/balinterdi/twuckoo"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.4.0
@@ -17,7 +17,7 @@ module OneLineFromFile
17
17
  def load_tweets
18
18
  load_lines
19
19
  end
20
-
20
+
21
21
  def get_lines_from_file
22
22
  begin
23
23
  IO::readlines(LINES_FILE).map { |line| line.chomp }
@@ -42,10 +42,12 @@ module OneLineFromFile
42
42
  @used_lines ||= get_used_lines_from_file
43
43
  end
44
44
 
45
+ def get_unused_lines
46
+ get_all_lines.reject { |line| get_used_lines.include?(line) }
47
+ end
48
+
45
49
  def load_lines
46
- used = get_used_lines
47
- unused_lines = get_all_lines.select { |line| !used.include?(line) }
48
- add_lines(*unused_lines)
50
+ add_lines(*get_unused_lines)
49
51
  end
50
52
 
51
53
  def add_lines(*new_lines)
@@ -66,5 +68,10 @@ module OneLineFromFile
66
68
  @lines.delete_at(pick)
67
69
  end
68
70
 
71
+ def reset
72
+ File.delete(USED_LINES_FILE) rescue nil
73
+ @used_lines = nil
74
+ load_lines
75
+ end
69
76
  end
70
77
 
@@ -1,5 +1,6 @@
1
1
  class Twuckoo::Config < Hash
2
2
  def initialize
3
3
  self[:time_to_sleep] = "1d"
4
+ self[:tweet_limit] = 0
4
5
  end
5
6
  end
@@ -11,26 +11,39 @@ class Twuckoo::Runner
11
11
  # - load_tweets
12
12
  # - next
13
13
  # - store(tweet)
14
- attr_reader :used_module
15
14
 
16
15
  def run
17
16
  setup_from_file
18
17
  load_tweets
19
18
  next_tweet = self.next
20
- while next_tweet do
19
+ while (next_tweet and !tweet_limit_reached?) do
21
20
  tweet(next_tweet)
21
+ inc_tweet_counter
22
22
  wait if wait_between_tweets?
23
23
  next_tweet = self.next
24
- notify if next_tweet.nil?
24
+ if next_tweet.nil?
25
+ notify
26
+ reset
27
+ next_tweet = self.next
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.create(args=[])
33
+ module_name = args.first
34
+ unless module_name.nil?
35
+ _module = get_module(module_name)
36
+ class_eval { include _module }
25
37
  end
38
+ new(args)
26
39
  end
27
40
 
28
- def initialize(args=[])
41
+ attr_accessor :tweets_sent
42
+
43
+ def initialize(args=[])
44
+ @tweets_sent = 0
29
45
  @options = OpenStruct.new
30
46
  parse_options!(args)
31
-
32
- _module = args.pop
33
- use_module(get_module(_module))
34
47
  super
35
48
  end
36
49
 
@@ -44,7 +57,7 @@ class Twuckoo::Runner
44
57
  opts.on_tail("-h", "--help", "Show this message") do
45
58
  puts opts
46
59
  exit
47
- end
60
+ end
48
61
  end
49
62
 
50
63
  if args.length.zero?
@@ -57,13 +70,13 @@ class Twuckoo::Runner
57
70
  # exit
58
71
  # end
59
72
 
60
- opts.parse!(args)
73
+ opts.parse!(args)
61
74
  end
62
-
75
+
63
76
  def name
64
77
  @options.name || File.split(File.dirname(__FILE__)).last
65
78
  end
66
-
79
+
67
80
  def wait_between_tweets?
68
81
  config[:time_to_sleep] != "0"
69
82
  end
@@ -76,7 +89,7 @@ class Twuckoo::Runner
76
89
  def notify
77
90
  send_email(name, config)
78
91
  end
79
-
92
+
80
93
  def tweet(message)
81
94
  unless message.nil? or message.empty?
82
95
  store(message)
@@ -112,8 +125,8 @@ class Twuckoo::Runner
112
125
  end
113
126
 
114
127
  private
115
- def get_module(module_id)
116
- case module_id
128
+ def self.get_module(module_name)
129
+ case module_name
117
130
  when "file"
118
131
  OneLineFromFile
119
132
  when "from_file"
@@ -121,19 +134,22 @@ class Twuckoo::Runner
121
134
  when "wikipedia_tfa"
122
135
  WikipediaTFA
123
136
  else
124
- raise TwuckooException, "Invalid module: #{module_id.inspect}"
137
+ raise TwuckooException, "Invalid module: #{module_name.inspect}"
125
138
  end
126
139
  end
127
-
128
- def use_module(_module)
129
- @used_module = _module
130
- self.class.class_eval { include _module }
131
- end
132
140
 
133
141
  def send_tweet(message)
134
142
  twitter.status(:post, message)
135
143
  end
136
144
 
145
+ def inc_tweet_counter
146
+ @tweets_sent += 1
147
+ end
148
+
149
+ def tweet_limit_reached?
150
+ !config[:tweet_limit].zero? and config[:tweet_limit].to_i == tweets_sent
151
+ end
152
+
137
153
  def send_email(name, config)
138
154
  Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
139
155
  Mail.defaults do
@@ -2,11 +2,15 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe "A cuckoo twitterer with one line from a file" do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.new(["file"])
5
+ @twuckoo = Twuckoo::Runner.create(["file"])
6
6
  # just so that no files will be written
7
7
  @twuckoo.stubs(:store).returns(nil)
8
8
  # and the actual text tweets are not tweeted (twittered?)
9
9
  @twuckoo.stubs(:send_tweet).returns(true)
10
+ @twuckoo.stubs(:send_email).returns(true)
11
+ @twuckoo.setup do |config|
12
+ config[:time_to_sleep] = "0"
13
+ end
10
14
  end
11
15
 
12
16
  it "stores a line that was sent to it correctly" do
@@ -85,4 +89,33 @@ describe "A cuckoo twitterer with one line from a file" do
85
89
  end
86
90
  end
87
91
  end
92
+
93
+ describe "when there is nothing left to tweet" do
94
+ before do
95
+ @twuckoo.stubs(:next).returns("tweet me this").then.returns(nil)
96
+ @twuckoo.stubs(:load_tweets).returns(nil)
97
+ end
98
+
99
+ it "does not call store" do
100
+ @twuckoo.expects(:store).once
101
+ @twuckoo.run
102
+ end
103
+
104
+ it "calls reset" do
105
+ @twuckoo.expects(:reset).once
106
+ @twuckoo.run
107
+ end
108
+
109
+ end
110
+
111
+ it "loads the lines when reset" do
112
+ pending
113
+ @twuckoo.stubs(:get_unused_lines).returns(["tweet me this", "tweet me that"])
114
+ @twuckoo.setup do |config|
115
+ config[:tweet_limit] = 2
116
+ end
117
+ @twuckoo.expects(:tweet).times(5)
118
+ @twuckoo.run
119
+ end
120
+
88
121
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
3
  describe Twuckoo::Runner do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.new(["file"])
5
+ @twuckoo = Twuckoo::Runner.create(["file"])
6
6
  # actual text tweets should not be tweeted (twittered?)
7
7
  @twuckoo.stubs(:send_tweet).returns(true)
8
8
  end
@@ -25,7 +25,7 @@ describe Twuckoo::Runner do
25
25
  config[:time_to_sleep] = "1h"
26
26
  end
27
27
  #TODO: write a custom matcher so this could be written as:
28
- # @twuckoo.should_not wait_between_tweets
28
+ # @twuckoo.should_not wait_between_tweets
29
29
  @twuckoo.wait_between_tweets?.should == true
30
30
  end
31
31
 
@@ -36,11 +36,22 @@ describe Twuckoo::Runner do
36
36
  @twuckoo.config[:time_to_sleep].should == "3m"
37
37
  end
38
38
 
39
+ it "can be made to tweet only a certain number of times" do
40
+ @twuckoo.stubs(:store).returns(nil)
41
+ @twuckoo.stubs(:wait_between_tweets?).returns(false)
42
+ @twuckoo.stubs(:next).returns("tweet me this")
43
+ @twuckoo.setup do |config|
44
+ config[:tweet_limit] = 2
45
+ end
46
+ @twuckoo.expects(:tweet).times(2)
47
+ @twuckoo.run
48
+ end
49
+
39
50
  it "should receive the module to use as the last parameter" do
40
51
  runner = Twuckoo::Runner.new(%w[file])
41
- runner.used_module.should == OneLineFromFile
52
+ runner.should respond_to(:reset)
42
53
  end
43
-
54
+
44
55
  it "name can be given through the -n option" do
45
56
  runner = Twuckoo::Runner.new(%w[-n pragthinklearn file])
46
57
  runner.name.should == "pragthinklearn"
@@ -50,7 +61,7 @@ describe Twuckoo::Runner do
50
61
  runner = Twuckoo::Runner.new(%w[file])
51
62
  runner.name.should == "twuckoo"
52
63
  end
53
-
64
+
54
65
  describe "loading values from the config file" do
55
66
  it "sets the time interval to wait b/w tweets correctly" do
56
67
  @twuckoo.expects(:get_config_values_from_file).returns({ :time_to_sleep => "3m" })
@@ -59,17 +70,6 @@ describe Twuckoo::Runner do
59
70
  end
60
71
  end
61
72
 
62
- describe "when there is nothing to tweet" do
63
- before do
64
- @twuckoo.stubs(:next).returns(nil)
65
- @twuckoo.stubs(:load_tweets).returns(nil)
66
- end
67
- it "does not call store" do
68
- @twuckoo.expects(:store).never
69
- @twuckoo.run
70
- end
71
- end
72
-
73
73
  describe "when there is nothing more to tweet after a while" do
74
74
  before do
75
75
  @twuckoo.setup do |config|
@@ -83,5 +83,5 @@ describe Twuckoo::Runner do
83
83
  @twuckoo.run
84
84
  end
85
85
  end
86
-
86
+
87
87
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe "A cuckoo twitterer for wikipedia featured article" do
4
4
  before do
5
- @twuckoo = Twuckoo::Runner.new(["wikipedia_tfa"])
5
+ @twuckoo = Twuckoo::Runner.create(["wikipedia_tfa"])
6
6
  @twuckoo.setup do |config|
7
7
  config[:time_to_sleep] = "0"
8
8
  end
data/twuckoo.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twuckoo}
8
- s.version = "0.3.5"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Balint Erdi"]
12
- s.date = %q{2010-01-18}
12
+ s.date = %q{2010-04-26}
13
13
  s.default_executable = %q{twuckoo}
14
- s.description = %q{ A simple yet elegant solution to tweet a message regularly from a file (from a webpage, a database, etc.)
14
+ s.description = %q{ A simple yet elegant solution to tweet a message regularly from a file (or from a webpage, a database, etc.)
15
15
  }
16
16
  s.email = %q{balint.erdi@gmail.com}
17
17
  s.executables = ["twuckoo"]
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  s.homepage = %q{http://github.com/balinterdi/twuckoo}
49
49
  s.rdoc_options = ["--charset=UTF-8"]
50
50
  s.require_paths = ["lib"]
51
- s.rubygems_version = %q{1.3.5}
51
+ s.rubygems_version = %q{1.3.6}
52
52
  s.summary = %q{Need to tweet periodically in an automated fashion? Then Twuckoo is for you!}
53
53
  s.test_files = [
54
54
  "spec/duration_string_spec.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twuckoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Balint Erdi
@@ -9,70 +14,92 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-18 00:00:00 +01:00
17
+ date: 2010-04-26 00:00:00 +02:00
13
18
  default_executable: twuckoo
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: mocha
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 5
23
31
  version: 0.9.5
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
33
43
  version: "0"
34
- version:
44
+ type: :development
45
+ version_requirements: *id002
35
46
  - !ruby/object:Gem::Dependency
36
47
  name: twibot
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
40
50
  requirements:
41
51
  - - ">="
42
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ - 1
56
+ - 7
43
57
  version: 0.1.7
44
- version:
58
+ type: :runtime
59
+ version_requirements: *id003
45
60
  - !ruby/object:Gem::Dependency
46
61
  name: hpricot
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - ">="
52
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ - 6
70
+ - 164
53
71
  version: 0.6.164
54
- version:
72
+ type: :runtime
73
+ version_requirements: *id004
55
74
  - !ruby/object:Gem::Dependency
56
75
  name: mail
57
- type: :runtime
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
60
78
  requirements:
61
79
  - - ">="
62
80
  - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 6
84
+ - 0
63
85
  version: 1.6.0
64
- version:
86
+ type: :runtime
87
+ version_requirements: *id005
65
88
  - !ruby/object:Gem::Dependency
66
89
  name: tlsmail
67
- type: :runtime
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
70
92
  requirements:
71
93
  - - ">="
72
94
  - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ - 0
98
+ - 1
73
99
  version: 0.0.1
74
- version:
75
- description: " A simple yet elegant solution to tweet a message regularly from a file (from a webpage, a database, etc.)\n"
100
+ type: :runtime
101
+ version_requirements: *id006
102
+ description: " A simple yet elegant solution to tweet a message regularly from a file (or from a webpage, a database, etc.)\n"
76
103
  email: balint.erdi@gmail.com
77
104
  executables:
78
105
  - twuckoo
@@ -119,18 +146,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
146
  requirements:
120
147
  - - ">="
121
148
  - !ruby/object:Gem::Version
149
+ segments:
150
+ - 0
122
151
  version: "0"
123
- version:
124
152
  required_rubygems_version: !ruby/object:Gem::Requirement
125
153
  requirements:
126
154
  - - ">="
127
155
  - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
128
158
  version: "0"
129
- version:
130
159
  requirements: []
131
160
 
132
161
  rubyforge_project:
133
- rubygems_version: 1.3.5
162
+ rubygems_version: 1.3.6
134
163
  signing_key:
135
164
  specification_version: 3
136
165
  summary: Need to tweet periodically in an automated fashion? Then Twuckoo is for you!