replacer_bot 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3f27f98339571d3f2f02f50776049785f1d52bb
4
- data.tar.gz: 36a8af3bc649a8d18f9d1e59d19f6d715220e466
3
+ metadata.gz: f452a58e1674155cdd4bf1b6f731a72929e9e518
4
+ data.tar.gz: d7585edd12a9ea3964e5aec9fbf69fe452bc2fd2
5
5
  SHA512:
6
- metadata.gz: 1f8edccc8fb420dc44c9d58e931e8117cb677092879541df343e229e3a556b0ca49a379c03132446ab6d18026a80ece5eddf6b4ff52e89ee04f8beb5322e14b2
7
- data.tar.gz: 3133bd60c3169fb6478a8a1422a9bb1d2ff0dbd23624ef75ceab47800a836fbd0c5595d6f92c2b5c50fb71d9eb18354746fe6873c637ba80e4ea5b80d4b74e02
6
+ metadata.gz: 0e7cc282da55a9405a03e5ee6aad6ab13fbf2803eeb9e67584d53a3a8a309ef8dc46cb63337c32d763b52909ed219239fb27f337cd94e7dcd0cd7bb547500a75
7
+ data.tar.gz: 74f26e404d32ebda0a33e4d3857f24013f3ce99ed2e8123f6b71fa9a51a1ad16b2a2b1125dfb515f82aa2f0d46a2304095ef5c65cb30ef3d6f63516d2db43af0
data/README.md CHANGED
@@ -5,3 +5,39 @@
5
5
  [![Gem Version](http://img.shields.io/gem/v/replacer_bot.svg)](https://rubygems.org/gems/replacer_bot)
6
6
  [![License](http://img.shields.io/:license-mit-blue.svg)](http://pikesley.mit-license.org)
7
7
  [![Badges](http://img.shields.io/:badges-7/7-ff6799.svg)](https://github.com/badges/badgerbadgerbadger)
8
+
9
+ # Replacer Bot
10
+
11
+ Twitter bot that:
12
+
13
+ * Searches Twitter for a phrase
14
+ * Search-and-replaces phrases in the tweets
15
+ * Tweets them
16
+
17
+ ## Configuration
18
+
19
+ The default config is [here](https://github.com/pikesley/replacer_bot/blob/master/config/defaults.yml), you'll want to create your own config at `~/.replacer_bot/config.yml`, something like:
20
+
21
+ search_term: David Cameron
22
+ replacements:
23
+ - david cameron: "Satan's Little Helper"
24
+ - cameron: Satan
25
+ save_file: /Users/sam/.replacer_bot/last.tweet
26
+
27
+ You'll also need some Twitter credentials, store them in `~/.replacer_botrc` like this:
28
+
29
+ CONSUMER_KEY: some_key
30
+ CONSUMER_SECRET: some_secret
31
+ TOKEN: oauth_token
32
+ SECRET: oauth_secret
33
+
34
+ (and see [this](http://dghubble.com/blog/posts/twitter-app-write-access-and-bots/) for help on setting up Twitter bots)
35
+
36
+ ## Running it
37
+
38
+ You should now be able to do run it like so:
39
+
40
+ ➔ replacer tweet
41
+ Tweeting: Satan's Little Helper sets out academy 'vision' for every school http://t.co/S6yFWRf7pD
42
+ Sleeping 60 seconds
43
+ Tweeting: Swarm warning: Satan's Little Helper accuses migrants of 'breaking in' to UK http://t.co/1sB5J8Alwi
data/config/defaults.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  search_term: open data
2
+ search_count: 100
3
+ ignore_spaces: true
2
4
  save_file: last.tweet
3
5
  replacements:
4
6
  - open data: Taylor Swift
@@ -23,8 +23,8 @@ module ReplacerBot
23
23
  false
24
24
  end
25
25
 
26
- def self.filter list
27
- list.select { |i| self.validate i.text, Config.instance.config.search_term }.
26
+ def self.filter list, ignore_spaces = true
27
+ list.select { |i| self.validate i.text, Config.instance.config.search_term, ignore_spaces }.
28
28
  select { |i| i.id > self.last_tweet}
29
29
  end
30
30
 
@@ -8,9 +8,9 @@ module ReplacerBot
8
8
  @client = TwitterClient.client
9
9
  end
10
10
 
11
- def search count = 20
11
+ def search #count = 20
12
12
  @results ||= begin
13
- results = ReplacerBot.filter @client.search(ReplacerBot.encode(@search_term), result_type: 'recent').take(count)
13
+ results = ReplacerBot.filter @client.search(ReplacerBot.encode(@search_term), result_type: 'recent').take(@config.search_count), @config.ignore_spaces
14
14
  end
15
15
  end
16
16
 
@@ -19,11 +19,13 @@ module ReplacerBot
19
19
  end
20
20
 
21
21
  def tweet
22
- tweets.each do |tweet|
22
+ tweets.each_with_index do |tweet, index|
23
23
  puts "Tweeting: #{tweet}"
24
24
  @client.update tweet
25
- puts "Sleeping #{@config.interval} seconds"
26
- sleep @config.interval
25
+ unless index == tweets.count - 1
26
+ puts "Sleeping #{@config.interval} seconds"
27
+ sleep @config.interval
28
+ end
27
29
  end
28
30
 
29
31
  save
@@ -31,6 +33,7 @@ module ReplacerBot
31
33
 
32
34
  def save
33
35
  if search.first
36
+
34
37
  File.open @config.save_file, 'w' do |file|
35
38
  Marshal.dump search.first.id, file
36
39
  end
@@ -1,3 +1,3 @@
1
1
  module ReplacerBot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/replacer_bot.rb CHANGED
@@ -12,5 +12,6 @@ require 'replacer_bot/helpers'
12
12
  require 'replacer_bot/twitter_client'
13
13
 
14
14
  Dotenv.load
15
+ Dotenv.load "#{ENV['HOME']}/.replacer_botrc"
15
16
 
16
17
  TWITTER_LIMIT= 140
@@ -63,6 +63,7 @@ module ReplacerBot
63
63
  it 'prepares sensible tweets', :vcr do
64
64
  expect(replacer.tweets).to be_a Array
65
65
  expect(replacer.tweets.first).to eq 'Taylor Swift Hackathon 6-7 октября'
66
+ expect(replacer.tweets[27]).to eq 'CompTIA_SLED: RT CADeptTech: Building a User-Centric #California #Government through Demand-Driven #TaylorSwift http://t.co/mh91wbk4xK ---…'
66
67
  expect(replacer.tweets.all? { |t| t.length <= 140} ).to eq true
67
68
  end
68
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replacer_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley