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 +4 -4
- data/README.md +36 -0
- data/config/defaults.yml +2 -0
- data/lib/replacer_bot/helpers.rb +2 -2
- data/lib/replacer_bot/replacer.rb +8 -5
- data/lib/replacer_bot/version.rb +1 -1
- data/lib/replacer_bot.rb +1 -0
- data/spec/lib/replacer_bot/replacer_spec.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f452a58e1674155cdd4bf1b6f731a72929e9e518
|
4
|
+
data.tar.gz: d7585edd12a9ea3964e5aec9fbf69fe452bc2fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7cc282da55a9405a03e5ee6aad6ab13fbf2803eeb9e67584d53a3a8a309ef8dc46cb63337c32d763b52909ed219239fb27f337cd94e7dcd0cd7bb547500a75
|
7
|
+
data.tar.gz: 74f26e404d32ebda0a33e4d3857f24013f3ce99ed2e8123f6b71fa9a51a1ad16b2a2b1125dfb515f82aa2f0d46a2304095ef5c65cb30ef3d6f63516d2db43af0
|
data/README.md
CHANGED
@@ -5,3 +5,39 @@
|
|
5
5
|
[](https://rubygems.org/gems/replacer_bot)
|
6
6
|
[](http://pikesley.mit-license.org)
|
7
7
|
[](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
data/lib/replacer_bot/helpers.rb
CHANGED
@@ -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(
|
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.
|
22
|
+
tweets.each_with_index do |tweet, index|
|
23
23
|
puts "Tweeting: #{tweet}"
|
24
24
|
@client.update tweet
|
25
|
-
|
26
|
-
|
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
|
data/lib/replacer_bot/version.rb
CHANGED
data/lib/replacer_bot.rb
CHANGED
@@ -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
|