robotwitter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -2
- data/VERSION +1 -0
- data/example/settings.yaml +5 -0
- data/example/test.rb +7 -0
- data/lib/robotwitter.rb +18 -14
- data/lib/robotwitter/db.rb +44 -0
- data/lib/robotwitter/path.rb +13 -0
- data/lib/robotwitter/version.rb +3 -0
- data/robotwitter.gemspec +74 -0
- data/spec/robotwitter/robotwitter_spec.rb +39 -2
- data/spec/spec_helper.rb +1 -1
- metadata +11 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Robotwitter
|
2
2
|
|
3
|
-
Robotwitter makes it easer to
|
3
|
+
Robotwitter makes it easer to automate some twitter functions, such as:
|
4
4
|
* creating tweets
|
5
5
|
* retweeting by keywords
|
6
6
|
* follow back who follows you
|
@@ -10,7 +10,9 @@ Robotwitter makes it easer to robust some twitter functions, such as:
|
|
10
10
|
|
11
11
|
* gem install robotwitter
|
12
12
|
|
13
|
-
|
13
|
+
Robotwitter::Path.set_base your_path_to_cofing
|
14
|
+
|
15
|
+
client = Robotwitter::Robot.new "settings.yaml", "your_twitter_login", &GETTER
|
14
16
|
&GETTER could be nil (see below)
|
15
17
|
|
16
18
|
client.follow_all_back
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/example/test.rb
ADDED
data/lib/robotwitter.rb
CHANGED
@@ -5,6 +5,10 @@ require 'pp'
|
|
5
5
|
require 'yaml'
|
6
6
|
require 'sqlite3'
|
7
7
|
|
8
|
+
require "robotwitter/db"
|
9
|
+
require "robotwitter/path"
|
10
|
+
require "robotwitter/version"
|
11
|
+
|
8
12
|
module Robotwitter
|
9
13
|
class Robot
|
10
14
|
attr_accessor :stub
|
@@ -18,22 +22,26 @@ module Robotwitter
|
|
18
22
|
# db = SQLite3::Database.new("database.db")
|
19
23
|
# db.get_first_row( "select * from table" )
|
20
24
|
# end
|
21
|
-
def initialize
|
25
|
+
def initialize config_file, section, &getter
|
22
26
|
@getter = getter
|
23
27
|
@followers_ids = nil
|
24
28
|
@following_ids = nil
|
25
29
|
|
26
30
|
@stub = false
|
27
31
|
|
28
|
-
|
32
|
+
begin
|
33
|
+
yml = YAML.load_file Robotwitter::Path.get_base + '/' + config_file
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
Twitter.configure do |config|
|
36
|
+
config.consumer_key = yml[section]['consumer_key']
|
37
|
+
config.consumer_secret = yml[section]['consumer_secret']
|
38
|
+
config.oauth_token = yml[section]['oauth_token']
|
39
|
+
config.oauth_token_secret = yml[section]['oauth_token_secret']
|
40
|
+
end
|
41
|
+
@client = Twitter::Client.new
|
42
|
+
rescue
|
43
|
+
print 'error occurred: ' + $!
|
35
44
|
end
|
36
|
-
@client = Twitter::Client.new
|
37
45
|
end
|
38
46
|
|
39
47
|
# follow who follows me
|
@@ -60,10 +68,6 @@ module Robotwitter
|
|
60
68
|
pp send
|
61
69
|
end
|
62
70
|
|
63
|
-
def send_message_mention pattern
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
71
|
def retweet_about word
|
68
72
|
search = search_users_tweets_about(word, 2)
|
69
73
|
init_db
|
@@ -115,7 +119,7 @@ module Robotwitter
|
|
115
119
|
protected
|
116
120
|
|
117
121
|
def init_db
|
118
|
-
@db = Db.new('tweets') if @db.nil?
|
122
|
+
@db = Robotwitter::Db.new('tweets') if @db.nil?
|
119
123
|
@db
|
120
124
|
end
|
121
125
|
|
@@ -150,7 +154,7 @@ module Robotwitter
|
|
150
154
|
begin
|
151
155
|
@client.retweet(result['id']) unless @stub
|
152
156
|
rescue
|
153
|
-
puts 'error'
|
157
|
+
puts 'error: ' + $!
|
154
158
|
end
|
155
159
|
end
|
156
160
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Robotwitter
|
2
|
+
class Db
|
3
|
+
TABLENAME = 'retweeted'
|
4
|
+
|
5
|
+
# check if database exists
|
6
|
+
def exists?(name)
|
7
|
+
File.exist?("#{name}.db")
|
8
|
+
end
|
9
|
+
|
10
|
+
# create database
|
11
|
+
def create_db(name)
|
12
|
+
db = SQLite3::Database.new("#{name}.db")
|
13
|
+
|
14
|
+
sql = <<SQL
|
15
|
+
create table #{TABLENAME} (
|
16
|
+
id integer PRIMARY KEY AUTOINCREMENT,
|
17
|
+
tweet_id string
|
18
|
+
);
|
19
|
+
SQL
|
20
|
+
|
21
|
+
db.execute_batch(sql)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(name)
|
25
|
+
create_db("#{Robotwitter::Path.get_base}/#{name}") unless exists? "#{Robotwitter::Path.get_base}/#{name}"
|
26
|
+
@db = SQLite3::Database.new "#{Robotwitter::Path.get_base}/#{name}.db"
|
27
|
+
end
|
28
|
+
|
29
|
+
# already retweeted this post
|
30
|
+
def retweeted? result
|
31
|
+
sql = "select 1 from #{TABLENAME} where tweet_id = '#{result['id_str']}'"
|
32
|
+
res = @db.get_first_row(sql)
|
33
|
+
!res.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
# сохраняем ретвитт, чтобы не ретвиттить снова
|
37
|
+
# result - результат twitter.search
|
38
|
+
def save_retweet result
|
39
|
+
id = result['id_str']
|
40
|
+
sql = "insert into #{TABLENAME} (tweet_id) values (#{id})"
|
41
|
+
@db.query(sql)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/robotwitter.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{robotwitter}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Krivich Ekaterina"]
|
12
|
+
s.date = %q{2011-04-23}
|
13
|
+
s.description = %q{automate twitter tasks, such as retweetting, following, unfollowing}
|
14
|
+
s.email = %q{krivich.ekaterina@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"example/settings.yaml",
|
27
|
+
"example/test.rb",
|
28
|
+
"lib/robotwitter.rb",
|
29
|
+
"lib/robotwitter/db.rb",
|
30
|
+
"lib/robotwitter/path.rb",
|
31
|
+
"lib/robotwitter/version.rb",
|
32
|
+
"robotwitter.gemspec",
|
33
|
+
"spec/robotwitter/robotwitter_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/kiote/robotwitter}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{automate some twitter tasks}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/robotwitter/robotwitter_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<twitter>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
59
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<twitter>, [">= 0"])
|
67
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
68
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -2,7 +2,44 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Robotwitter" do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
context "with nil POSTER" do
|
6
|
+
|
7
|
+
POSTER = nil
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
settings_path = File.expand_path('../../../example', __FILE__)
|
11
|
+
@client = Robotwitter::Robot.new "#{settings_path}/settings.yaml", 'test_login', &POSTER
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create new object on right init params" do
|
15
|
+
@client.class.to_s.should eq("Robotwitter::Robot")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should follows those who follows me" do
|
19
|
+
pending "get the mock for twitter" do
|
20
|
+
@client.follow_all_back
|
21
|
+
a_request(:get, "https://search.twitter.com/search.json").
|
22
|
+
with(:query => {:q => "twitter"}).
|
23
|
+
should have_been_made
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should tweet a message" do
|
28
|
+
pending("get the mock for twitter")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should retweet about word" do
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should follow users tweets about" do
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should unfollow users who did not following me" do
|
40
|
+
|
41
|
+
end
|
7
42
|
end
|
43
|
+
|
44
|
+
|
8
45
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robotwitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Krivich Ekaterina
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-23 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -121,7 +121,14 @@ files:
|
|
121
121
|
- LICENSE.txt
|
122
122
|
- README.rdoc
|
123
123
|
- Rakefile
|
124
|
+
- VERSION
|
125
|
+
- example/settings.yaml
|
126
|
+
- example/test.rb
|
124
127
|
- lib/robotwitter.rb
|
128
|
+
- lib/robotwitter/db.rb
|
129
|
+
- lib/robotwitter/path.rb
|
130
|
+
- lib/robotwitter/version.rb
|
131
|
+
- robotwitter.gemspec
|
125
132
|
- spec/robotwitter/robotwitter_spec.rb
|
126
133
|
- spec/spec_helper.rb
|
127
134
|
has_rdoc: true
|