replacer_bot 0.0.15 → 0.1.1.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/replacer_bot/helpers.rb +15 -1
- data/lib/replacer_bot/version.rb +1 -1
- data/replacer_bot.gemspec +2 -2
- data/spec/lib/replacer_bot/advanced_search_spec.rb +35 -0
- data/spec/lib/replacer_bot/helpers_spec.rb +7 -0
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_English_tweets.yml +1364 -0
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_the_correct_tweets.yml +1364 -0
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_tweets.yml +2782 -0
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/searches_for_tweets.yml +1364 -0
- metadata +19 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2a369cf5d62f75a206c64ec2f2fed6490b688c3
|
4
|
+
data.tar.gz: ace466966daaf290e16b44055d7dd41b64267474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae3d0d9c21d8f7059ce1bf76fc22d226edcc8ba4364389b1b0851ff4830f881c69910617bc8d2ae3934766d8abcd442c6b9f0133a5763b966837d06f26731b4
|
7
|
+
data.tar.gz: e0823bf012f30e62ebd4f8eb4f2d33fe9f2c57a522e8a11d3770d57c9370a68bd3a2bfa521db52a630445b8bea74fa8ee16039f243a16e411343da9090c6de65
|
data/README.md
CHANGED
@@ -77,8 +77,8 @@ which does the search and shows what it would have tweeted, without actually twe
|
|
77
77
|
|
78
78
|
It turns out that a lot of Twitter is people (or bots) retweeting the same stuff with minimal changes, like adding extra hashtags or using a different URL shortener (I don't really understand how this even happens, but whatever). (Actually, I wonder how much of Twitter is just bots yelling at each other in the void. But I digress.) This makes a crude 'search for this phrase' bot _extremely_ noisy, so I have come up with some Opinions based on some very crude Reckons. Things that will make the bot consider tweets to be 'the same' as tweets we've seen before, and therefore ignorable, are:
|
79
79
|
|
80
|
-
* They match save for
|
81
|
-
* They match save for different hashtags at the _start_ and _end_ of the tweet (hashtags in the body of the tweet appear to be more relevant, based on my Reckons)
|
80
|
+
* They match, save for any URLs they contain being different
|
81
|
+
* They match, save for different hashtags at the _start_ and _end_ of the tweet (hashtags in the body of the tweet appear to be more relevant, based on my Reckons)
|
82
82
|
|
83
83
|
The above reduced the noise a bit, but not enough to make a substantial difference. So I came up with this:
|
84
84
|
|
data/lib/replacer_bot/helpers.rb
CHANGED
@@ -13,6 +13,7 @@ end
|
|
13
13
|
|
14
14
|
module ReplacerBot
|
15
15
|
def self.encode term:
|
16
|
+
return term if self.complex_search(string: term)
|
16
17
|
URI.encode "\"#{term}\""
|
17
18
|
end
|
18
19
|
|
@@ -39,8 +40,21 @@ module ReplacerBot
|
|
39
40
|
return false if string[0...2] == 'RT'
|
40
41
|
return false if string[0] == '@'
|
41
42
|
|
42
|
-
|
43
|
+
unless self.complex_search(string: term)
|
44
|
+
term = term.gsub ' ', ' ?' if ignore_spaces
|
45
|
+
end
|
43
46
|
return true if string.index(/#{term}/i) && SeenTweets.validate(string)
|
47
|
+
return true if self.complex_search(string: term)
|
48
|
+
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.complex_search string:
|
53
|
+
['OR', 'AND'].map do |word|
|
54
|
+
if string.index " #{word} "
|
55
|
+
return true
|
56
|
+
end
|
57
|
+
end
|
44
58
|
|
45
59
|
false
|
46
60
|
end
|
data/lib/replacer_bot/version.rb
CHANGED
data/replacer_bot.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
30
30
|
spec.add_development_dependency 'guard-rspec', '~> 4.6'
|
31
31
|
spec.add_development_dependency 'guard-cucumber', '~> 1.6'
|
32
|
-
spec.add_development_dependency 'vcr', '~>
|
33
|
-
spec.add_development_dependency 'webmock', '~>
|
32
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
34
34
|
spec.add_development_dependency 'cucumber' , '~> 2.0'
|
35
35
|
spec.add_development_dependency 'aruba', '~> 0.8'
|
36
36
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ReplacerBot
|
2
|
+
describe Replacer do
|
3
|
+
before :each do
|
4
|
+
# Config.instance.config.search_term = "artificial intelligence AND (detect OR predict)"
|
5
|
+
Config.instance.config.search_term = "everton AND (koeman OR goodison)"
|
6
|
+
end
|
7
|
+
|
8
|
+
after :each do
|
9
|
+
FileUtils.rm_f Config.instance.config.save_file
|
10
|
+
FileUtils.rm_f Config.instance.config.seen_tweets
|
11
|
+
Config.instance.reset!
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'advanced search' do
|
15
|
+
let(:replacer) { described_class.new }
|
16
|
+
|
17
|
+
it 'searches for tweets', :vcr do
|
18
|
+
expect(replacer.search.class).to eq Array
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'finds tweets', :vcr do
|
22
|
+
expect(replacer.search.first.class).to eq Twitter::Tweet
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'finds the correct tweets', :vcr do
|
26
|
+
expect(replacer.search.first.text).to match /everton/i
|
27
|
+
# expect(replacer.search.all? { |tweet| tweet.text.match /everton/i }).to eq true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'finds English tweets', :vcr do
|
31
|
+
expect(replacer.search.all? { |tweet| tweet.lang == 'en' }).to eq true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -53,9 +53,16 @@ module ReplacerBot
|
|
53
53
|
it 'filters retweets' do
|
54
54
|
expect(ReplacerBot.validate string: 'RT @xyz This is about Open Data').to eq false
|
55
55
|
end
|
56
|
+
|
56
57
|
it 'filters direct replies' do
|
57
58
|
expect(ReplacerBot.validate string: '@abc This is a reply about Open Data').to eq false
|
58
59
|
end
|
60
|
+
|
61
|
+
it 'knows what a Complex Search is' do
|
62
|
+
expect(ReplacerBot.complex_search string: 'this OR that').to eq true
|
63
|
+
expect(ReplacerBot.complex_search string: 'this AND that').to eq true
|
64
|
+
expect(ReplacerBot.complex_search string: 'this, that').to eq false
|
65
|
+
end
|
59
66
|
end
|
60
67
|
|
61
68
|
context 'search and replace' do
|