rtbot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/rtbot +25 -0
- data/config.yml.example +6 -0
- data/lib/rtbot.rb +73 -0
- data/test/helper.rb +10 -0
- data/test/test_rtbot.rb +7 -0
- metadata +97 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 John Daniels
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= RTBot
|
2
|
+
|
3
|
+
RTBot is a simple way to make a Twitter retweeting bot.
|
4
|
+
|
5
|
+
You just call the 'rtbot' script and pass it the path to a YAML file with the configuration for the bot.
|
6
|
+
It does a Twitter search and retweets anything that matches.
|
7
|
+
|
8
|
+
After I wrote a script to do this the second time, I decided to make the third time much easier.
|
9
|
+
|
10
|
+
See config.yml.example for details on the configuration file.
|
11
|
+
|
12
|
+
= Example
|
13
|
+
|
14
|
+
Command:
|
15
|
+
|
16
|
+
rtbot --config=/home/john/bots/scotfail.yml
|
17
|
+
|
18
|
+
scotfail.yml:
|
19
|
+
|
20
|
+
consumer_key: 'actualconsumerkey' # consumer key from your Twitter app
|
21
|
+
consumer_secret: 'actualconsumersecret' # consumer secret from your Twitter app
|
22
|
+
access_token: 'actualaccesstoken' # access token from your Twitter app
|
23
|
+
access_token_secret: 'actualaccesstokensecret' # access token secret from your Twitter app
|
24
|
+
bot_name: 'scotfail' # Username of Twitter bot - used to prevent self-retweeting.
|
25
|
+
search_query: '#scotfail' # The Twitter search term
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2010 John Daniels. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rtbot"
|
8
|
+
gem.summary = %Q{A simple Twitter RTing bot.}
|
9
|
+
gem.description = %Q{Provides an rtbot script which you can configure to make a very simply Twitter retweeting bot.}
|
10
|
+
gem.email = "john@semantici.st"
|
11
|
+
gem.homepage = "http://github.com/johnd/rtbot"
|
12
|
+
gem.authors = ["John Daniels"]
|
13
|
+
gem.add_dependency "twitter", ">= 0"
|
14
|
+
gem.add_dependency "activesupport", ">= 2"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "rtbot #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/rtbot
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# RTBot
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require "#{File.dirname(__FILE__)}/../lib/rtbot"
|
6
|
+
require 'getoptlong'
|
7
|
+
|
8
|
+
opts = GetoptLong.new(['--config', '-c', GetoptLong::REQUIRED_ARGUMENT])
|
9
|
+
|
10
|
+
yaml_file_path = nil
|
11
|
+
|
12
|
+
opts.each do | opt, arg |
|
13
|
+
if opt == '--config'
|
14
|
+
if arg == ''
|
15
|
+
puts "Config File arugment is required."
|
16
|
+
exit 0
|
17
|
+
else
|
18
|
+
yaml_file_path = arg
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
rtbot = RTBot.new(yaml_file_path)
|
24
|
+
rtbot.run!
|
25
|
+
exit
|
data/config.yml.example
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
consumer_key: 'abc123def456ghi789' # consumer key from your Twitter app
|
2
|
+
consumer_secret: 'abc123def456ghi789jkl012mno345pqr678' # consumer secret from your Twitter app
|
3
|
+
access_token: '12345678-abc123def456ghi789jkl012mno345pqr678' # access token from your Twitter app
|
4
|
+
access_token_secret: 'abc123def456ghi789' # access token secret from your Twitter app
|
5
|
+
bot_name: 'scotfail' # Username of Twitter bot - used to prevent self-retweeting.
|
6
|
+
search_query: '#scotfail' # The Twitter search term
|
data/lib/rtbot.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
class RTBot
|
5
|
+
|
6
|
+
def initialize(yaml_file_path)
|
7
|
+
@config = YAML.load(File.read(yaml_file_path))
|
8
|
+
@config['last_id_path'] = "#{File.basename(yaml_file_path, File.extname(yaml_file_path))}.last_id" unless @config['last_id_path']
|
9
|
+
@config['log_path'] = "#{File.basename(yaml_file_path, File.extname(yaml_file_path))}.log" unless @config['log_path']
|
10
|
+
|
11
|
+
if File.exists?(@config['last_id_path'])
|
12
|
+
@last_read_id = File.new(@config['last_id_path'], 'r').gets
|
13
|
+
else
|
14
|
+
@last_read_id = 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_run
|
20
|
+
log = File.new(@config['log_path'], 'a')
|
21
|
+
|
22
|
+
log.puts "Test run at #{Time.now}"
|
23
|
+
|
24
|
+
search.each do | tweet |
|
25
|
+
log.puts tweet_text = "RT @#{tweet.from_user}: #{tweet.text}".first(139)
|
26
|
+
end
|
27
|
+
|
28
|
+
log.close
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def run!
|
33
|
+
@log = File.new(@config['log_path'], 'a')
|
34
|
+
|
35
|
+
tweet authenticate, search
|
36
|
+
|
37
|
+
@log.close
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def authenticate
|
45
|
+
oauth = Twitter::OAuth.new(@config['consumer_key'], @config['consumer_secret'])
|
46
|
+
oauth.authorize_from_access(@config['access_token'], @config['access_token_secret'])
|
47
|
+
return oauth
|
48
|
+
end
|
49
|
+
|
50
|
+
def search
|
51
|
+
Twitter::Search.new(@config['search_query']).since(@last_read_id).since_date(Date.today.strftime("%Y-%m-%d")).from(@config['bot_name'],true).to_a.reverse
|
52
|
+
end
|
53
|
+
|
54
|
+
def tweet(oauth,results)
|
55
|
+
|
56
|
+
|
57
|
+
@log.puts Time.now
|
58
|
+
|
59
|
+
results.each do | tweet |
|
60
|
+
client = Twitter::Base.new(oauth)
|
61
|
+
|
62
|
+
@log.puts tweet_text = "RT @#{tweet.from_user}: #{tweet.text}".first(139)
|
63
|
+
client.update(tweet_text)
|
64
|
+
@last_read_id = tweet.id
|
65
|
+
end
|
66
|
+
|
67
|
+
output = File.new(@config['last_id_path'], 'w')
|
68
|
+
output.write @last_read_id
|
69
|
+
output.close
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_rtbot.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- John Daniels
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-26 00:00:00 +01:00
|
18
|
+
default_executable: rtbot
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: twitter
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: activesupport
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 2
|
41
|
+
version: "2"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Provides an rtbot script which you can configure to make a very simply Twitter retweeting bot.
|
45
|
+
email: john@semantici.st
|
46
|
+
executables:
|
47
|
+
- rtbot
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files:
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- .document
|
55
|
+
- .gitignore
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- bin/rtbot
|
61
|
+
- config.yml.example
|
62
|
+
- lib/rtbot.rb
|
63
|
+
- test/helper.rb
|
64
|
+
- test/test_rtbot.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/johnd/rtbot
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.6
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: A simple Twitter RTing bot.
|
95
|
+
test_files:
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_rtbot.rb
|