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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5142e52860a2f9f8e4e0dbd21a00ca4cd7103eeb
4
- data.tar.gz: 304c8134e727d9f938bc1e24571bcd637d8b435c
3
+ metadata.gz: f2a369cf5d62f75a206c64ec2f2fed6490b688c3
4
+ data.tar.gz: ace466966daaf290e16b44055d7dd41b64267474
5
5
  SHA512:
6
- metadata.gz: 37d78ac5b7a4f875cf6d61439f05bf6d1ca8b3cd22140c19277b27790047004c442c4eac442607db0d8960e5e31cd640386a2b3b5e618412073b71e624aedd61
7
- data.tar.gz: 21b65ade44b9a06c1f811d10cc166a319dcb0e3c141e551c9255c5b268f61a7104d74b1f9998281fab36e704ab9037923df63a9720daf3f34654e26d4d1ab379
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 and 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)
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
 
@@ -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
- term = term.gsub ' ', ' ?' if ignore_spaces
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
@@ -1,3 +1,3 @@
1
1
  module ReplacerBot
2
- VERSION = "0.0.15"
2
+ VERSION = "0.1.1-rc1"
3
3
  end
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', '~> 2.9'
33
- spec.add_development_dependency 'webmock', '~> 1.21'
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