twitter_bot_generator 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +86 -29
- data/bin/twitter_bot_generator +16 -3
- data/lib/twitter_bot_generator/templates/.gitignore.erb +1 -1
- data/lib/twitter_bot_generator/templates/Gemfile.erb +1 -0
- data/lib/twitter_bot_generator/templates/README.md.erb +39 -0
- data/lib/twitter_bot_generator/templates/src/streaming-test_bot.rb.erb +11 -0
- data/lib/twitter_bot_generator/templates/src/test_bot.rb.erb +3 -1
- data/lib/twitter_bot_generator/templates/src/userstream-test_bot.rb.erb +11 -0
- data/lib/twitter_bot_generator/templates/streaming-bot.rb.erb +34 -0
- data/lib/twitter_bot_generator/templates/streaming-spec.rb.erb +9 -0
- data/lib/twitter_bot_generator/templates/test/streaming-test_bot_test.rb.erb +16 -0
- data/lib/twitter_bot_generator/templates/test/test_bot_test.rb.erb +4 -0
- data/lib/twitter_bot_generator/templates/test/userstream-test_bot_test.rb.erb +12 -0
- data/lib/twitter_bot_generator/templates/userstream-bot.rb.erb +28 -0
- data/lib/twitter_bot_generator/templates/userstream-spec.rb.erb +9 -0
- data/lib/twitter_bot_generator/version.rb +1 -1
- data/lib/twitter_bot_generator.rb +49 -14
- data/such_test_bot/.gitignore +3 -0
- data/such_test_bot/Gemfile +4 -0
- data/such_test_bot/Procfile +1 -0
- data/such_test_bot/README.md +44 -0
- data/such_test_bot/bot.rb +16 -0
- data/such_test_bot/lib/greetings.txt +3 -0
- data/such_test_bot/spec.rb +3 -0
- data/such_test_bot/src/such_test_bot.rb +25 -0
- data/such_test_bot/test/such_test_bot_test.rb +22 -0
- data/such_test_bot/test.rb +3 -0
- data/test/generated_default_bot.rb +9 -0
- data/test/generated_streaming_bot.rb +9 -0
- data/test/generated_userstream_bot.rb +9 -0
- data/test/scaffold_generator_test.rb +6 -1
- data/test/test_helper.rb +10 -7
- data/twitter_bot_generator.gemspec +17 -1
- metadata +42 -5
- data/test/generated_bot_test.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9354d645a4a295e9321481d95149c5a5d62653ba
|
4
|
+
data.tar.gz: 47d124b7b15a814c7b2f84982ddb190394baaaf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a25ce81c2b3142f8198e335d4a8b841208638c9b1f45cf182caf0b86fe10b74524b11c7410082eb5df75c32ce53f16157b5e847ce3576123c3eca768f6dd2257
|
7
|
+
data.tar.gz: b690edbf48ebae94bedf29ad9032b358e3a93d073a02c901eadbe14411ca2e0fba46ec4242b2645254b6586a59c08176d353ed11710df211873224453a8b1a90
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ cache: bundler
|
|
4
4
|
rvm:
|
5
5
|
- 2.0.0
|
6
6
|
|
7
|
-
script: 'bundle exec rake'
|
7
|
+
script: 'bundle exec rake && bundle exec ruby test/generated_default_bot.rb && bundle exec ruby test/generated_streaming_bot.rb && bundle exec ruby test/generated_userstream_bot.rb'
|
8
8
|
|
9
9
|
notifications:
|
10
10
|
email:
|
data/README.md
CHANGED
@@ -1,45 +1,102 @@
|
|
1
1
|
# twitter_bot_generator
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/twitter_bot_generator.svg)](http://badge.fury.io/rb/twitter_bot_generator)
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/coleww/twitter_bot_generator.svg?branch=master)](https://travis-ci.org/coleww/twitter_bot_generator)
|
6
|
+
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/coleww/twitter_bot_generator/badge.png?branch=master)](https://coveralls.io/r/coleww/twitter_bot_generator?branch=master)
|
8
|
+
|
3
9
|
#### I GENERATE TWITTER BOTS! RUBY IS JOY!
|
4
10
|
|
11
|
+
|
5
12
|
## Installation
|
6
13
|
|
7
14
|
$ gem install twitter_bot_generator
|
8
15
|
|
9
16
|
## Usage
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
18
|
+
```
|
19
|
+
$ twitter_bot_generator --help
|
20
|
+
twitter_bot_generator <yr_bots_name_camel_cased>
|
21
|
+
## creates a new directory called <yr_bots_name_camel_cased> in the current working directory,
|
22
|
+
and fills it with a bunch of boilerplate goodness
|
23
|
+
|
24
|
+
$ twitter_bot_generator wat_fun
|
25
|
+
scaffolding a twitter bot that is named wat_fun!
|
26
|
+
mkdir wat_fun/
|
27
|
+
mkdir wat_fun/lib
|
28
|
+
mkdir wat_fun/src
|
29
|
+
mkdir wat_fun/test
|
30
|
+
touch wat_fun/bot.rb
|
31
|
+
touch wat_fun/.gitignore
|
32
|
+
touch wat_fun/Gemfile
|
33
|
+
touch wat_fun/README.md
|
34
|
+
touch wat_fun/Procfile
|
35
|
+
touch wat_fun/spec.rb
|
36
|
+
touch wat_fun/test.rb
|
37
|
+
touch wat_fun/test/wat_fun_test.rb
|
38
|
+
touch wat_fun/src/wat_fun.rb
|
39
|
+
touch wat_fun/lib/greetings.txt
|
40
|
+
done generating! your turn now!
|
41
|
+
$ cd wat_fun
|
42
|
+
$ bundle install
|
43
|
+
$ ruby test.rb
|
44
|
+
$ ruby spec.rb
|
45
|
+
HAVE FUN BE SAFE PLAY NICE
|
46
|
+
```
|
47
|
+
|
48
|
+
This will create a skeleton class named YrBotNameSnakeCaseStyleYes, some smokescreen minitest::unit tests, and a variety of other "ruby app on free heroku instance" boiler plate.
|
49
|
+
|
50
|
+
## Deployment (heroku)
|
51
|
+
|
52
|
+
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
53
|
+
|
54
|
+
0. You probably need git and the heroku toolbet installed and also a heroku account.
|
55
|
+
0. Make a twitter account for your bot. Give it a photo and header and some biographical information
|
56
|
+
0. Go into settings > mobile and add a cell phone number that you can send a text from.
|
57
|
+
not all carriers will work :(
|
58
|
+
without a mobile number, twitter won't let you get the api keys you need to deploy
|
59
|
+
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
60
|
+
0. go to apps.twitter.com and sign in again
|
61
|
+
0. click create a new app
|
62
|
+
0. fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
63
|
+
0. once your app is created, click "modify app permissions" and set the app to read and write
|
64
|
+
0. wait a lil bit for permissions to change.......
|
65
|
+
0. click 'generate my access token'
|
66
|
+
0. wait a lil bit to get access tokens.....
|
67
|
+
0. SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
68
|
+
0. From the command line:
|
69
|
+
|
70
|
+
```
|
71
|
+
heroku create
|
72
|
+
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
73
|
+
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
74
|
+
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
75
|
+
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
76
|
+
```
|
77
|
+
|
78
|
+
0. go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
79
|
+
0. THE MAIN EVENT:
|
80
|
+
|
81
|
+
```
|
82
|
+
git push heroku master
|
83
|
+
heroku ps:scale bot=1
|
84
|
+
```
|
85
|
+
|
86
|
+
0. go to your bot's page and you should see it's first tweet! Or something?
|
40
87
|
|
41
88
|
This gem was made for use in the twitter-art-robot-[tutorial](http://github.com/coleww/twitter-art-tutorial) and more details and documentation and such will be there when things happen. :dancers:
|
42
89
|
|
90
|
+
Depends on:
|
91
|
+
|
92
|
+
https://github.com/sferik/twitter
|
93
|
+
|
94
|
+
And sometimes:
|
95
|
+
|
96
|
+
https://github.com/tweetstream/tweetstream
|
97
|
+
|
98
|
+
|
99
|
+
|
43
100
|
## Contribute
|
44
101
|
|
45
102
|
all kinds of issues in the thing to the upper right! =>
|
data/bin/twitter_bot_generator
CHANGED
@@ -3,13 +3,26 @@
|
|
3
3
|
require 'twitter_bot_generator'
|
4
4
|
|
5
5
|
begin
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
if !ARGV[0] || ARGV.any?{ |a| a == '--help' || a == '-H' }
|
8
|
+
puts 'twitter_bot_generator <yr_bots_name_camel_cased> (--<OPTIONAL OPTION>)'
|
8
9
|
puts '## creates a new directory called <yr_bots_name_camel_cased> in the current working directory, '
|
9
10
|
puts 'and fills it with a bunch of boilerplate goodness'
|
11
|
+
puts 'for building a bot that says stuff at a semi-random interval'
|
12
|
+
puts 'OPTIONAL ALTERNATIVE OPTIONS:'
|
13
|
+
puts '--streaming || -S: generates a bot that listens to the "gardenhose"'
|
14
|
+
puts '--userstream || -U: generates a bot that listens for tweets @ it'
|
15
|
+
puts 'have fun be kind to each other thanks goodbye!'
|
10
16
|
else
|
11
|
-
|
17
|
+
|
18
|
+
bot_name = ARGV[0].downcase.gsub(/[^a-z]/, '_')
|
19
|
+
|
20
|
+
TwitterBotGenerator.generate bot_name, ARGV[1] || ''
|
21
|
+
|
12
22
|
end
|
23
|
+
|
13
24
|
rescue
|
25
|
+
|
14
26
|
puts 'something horrible has happened'
|
27
|
+
|
15
28
|
end
|
@@ -1,5 +1,44 @@
|
|
1
1
|
# <%= bot_name %>
|
2
2
|
A Twitter Bot
|
3
3
|
|
4
|
+
## Development
|
5
|
+
|
4
6
|
> bundle install
|
5
7
|
> ruby test.rb
|
8
|
+
> ruby spec.rb
|
9
|
+
|
10
|
+
## Deployment (heroku)
|
11
|
+
|
12
|
+
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
13
|
+
|
14
|
+
0. You probably need git and the heroku toolbet installed and also a heroku account.
|
15
|
+
0. Make a twitter account for your bot. Give it a photo and header and some biographical information
|
16
|
+
0. Go into settings > mobile and add a cell phone number that you can send a text from.
|
17
|
+
not all carriers will work :(
|
18
|
+
without a mobile number, twitter won't let you get the api keys you need to deploy
|
19
|
+
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
20
|
+
0. go to apps.twitter.com and sign in again
|
21
|
+
0. click create a new app
|
22
|
+
0. fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
23
|
+
0. once your app is created, click "modify app permissions" and set the app to read and write
|
24
|
+
0. wait a lil bit to get access tokens
|
25
|
+
0. SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
26
|
+
0. From the command line:
|
27
|
+
|
28
|
+
```
|
29
|
+
heroku create
|
30
|
+
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
31
|
+
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
32
|
+
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
33
|
+
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
34
|
+
```
|
35
|
+
|
36
|
+
0. go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
37
|
+
0. THE MAIN EVENT:
|
38
|
+
|
39
|
+
```
|
40
|
+
git push heroku master
|
41
|
+
heroku ps:scale bot=1
|
42
|
+
```
|
43
|
+
|
44
|
+
0. go to your bot's page and you should see it's first tweet! Or something?
|
@@ -15,7 +15,9 @@ class <%= class_name %>
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def load_txt_file file_name
|
18
|
-
|
18
|
+
home_sweet_home = File.expand_path File.dirname __FILE__
|
19
|
+
ultimate_pathway = File.join home_sweet_home, '..', 'lib', file_name
|
20
|
+
(File.readlines ultimate_pathway).map &:strip
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'src/<%= bot_name %>.rb'
|
2
|
+
require "twitter"
|
3
|
+
require "tweetstream"
|
4
|
+
|
5
|
+
Twitter.configure do |config|
|
6
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
7
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
8
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
9
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
10
|
+
end
|
11
|
+
|
12
|
+
TweetStream.configure do |config|
|
13
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
14
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
15
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
16
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
17
|
+
config.auth_method = :oauth
|
18
|
+
end
|
19
|
+
|
20
|
+
loop do
|
21
|
+
begin
|
22
|
+
puts "starting search"
|
23
|
+
TweetStream::Client.new.sample(language: 'en') do |tweet|
|
24
|
+
if <%= class_name %>.matches? tweet.text
|
25
|
+
puts "got one!"
|
26
|
+
Twitter.retweet tweet.id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
puts 'FAILURE'
|
31
|
+
ensure
|
32
|
+
sleep 300
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative 'src/<%= bot_name %>'
|
3
|
+
|
4
|
+
puts "hello world! ?"
|
5
|
+
puts <%= class_name %>.matches? "hello world!"
|
6
|
+
puts "hello canada! ?"
|
7
|
+
puts <%= class_name %>.matches? "hello canada!"
|
8
|
+
puts "replace this with meaningful example strings to test yr app!"
|
9
|
+
puts <%= class_name %>.matches? "replace this with meaningful example strings to test yr app!"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
4
|
+
require_relative '../src/<%= bot_name %>.rb'
|
5
|
+
|
6
|
+
class Test<%= class_name %> < MiniTest::Test
|
7
|
+
|
8
|
+
def test_matches_hello_world
|
9
|
+
assert_equal true, (<%= class_name %>.matches? 'hello world')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_doesnt_match_hello_canada
|
13
|
+
assert_equal false, (<%= class_name %>.matches? 'hello canada')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
2
4
|
require_relative '../src/<%= bot_name %>.rb'
|
3
5
|
|
4
6
|
class Test<%= class_name %> < MiniTest::Test
|
@@ -9,10 +11,12 @@ class Test<%= class_name %> < MiniTest::Test
|
|
9
11
|
|
10
12
|
def test_hides_greetings
|
11
13
|
refute_respond_to <%= class_name %>, :greetings
|
14
|
+
assert_instance_of String, <%= class_name %>.send(:greetings)[0]
|
12
15
|
end
|
13
16
|
|
14
17
|
def test_hides_io_metal
|
15
18
|
refute_respond_to <%= class_name %>, :load_txt_file
|
19
|
+
assert_equal 3, <%= class_name %>.send(:load_txt_file, 'greetings.txt').length
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
4
|
+
require_relative '../src/<%= bot_name %>.rb'
|
5
|
+
|
6
|
+
class Test<%= class_name %> < MiniTest::Test
|
7
|
+
|
8
|
+
def test_reverses_hello_world
|
9
|
+
assert_match (<%= class_name %>.respond_to 'hello world'), 'dlrow olleh'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'src/<%= bot_name %>.rb'
|
2
|
+
require "twitter"
|
3
|
+
require "tweetstream"
|
4
|
+
|
5
|
+
Twitter.configure do |config|
|
6
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
7
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
8
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
9
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
10
|
+
end
|
11
|
+
|
12
|
+
TweetStream.configure do |config|
|
13
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
14
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
15
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
16
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
17
|
+
config.auth_method = :oauth
|
18
|
+
end
|
19
|
+
|
20
|
+
TweetStream::Client.new.userstream do |tweet|
|
21
|
+
puts "@#{tweet.user.screen_name} asks: #{tweet.text}"
|
22
|
+
begin
|
23
|
+
puts (answer = <%= class_name %>.respond_to tweet.text)
|
24
|
+
Twitter.update(answer, :in_reply_to_status_id => tweet.id)
|
25
|
+
rescue => e
|
26
|
+
puts e
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative 'src/<%= bot_name %>'
|
3
|
+
|
4
|
+
puts "hello world! ?"
|
5
|
+
puts <%= class_name %>.respond_to "hello world!"
|
6
|
+
puts "hello applesauce! ?"
|
7
|
+
puts <%= class_name %>.respond_to "hello applesauce!"
|
8
|
+
puts "replace this with meaningful example strings to test yr app!"
|
9
|
+
puts <%= class_name %>.respond_to "replace this with meaningful example strings to test yr app!"
|
@@ -6,21 +6,46 @@ class TwitterBotGenerator
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
|
9
|
-
def generate bot_name
|
10
|
-
|
9
|
+
def generate bot_name, flag=''
|
10
|
+
welcome_message bot_name, flag
|
11
|
+
make_directories! bot_name
|
12
|
+
write_files! bot_name, flag
|
13
|
+
exit_message bot_name
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def welcome_message bot_name, flag
|
19
|
+
descriptor = ''
|
20
|
+
if flag == '--streaming' || flag == '-S'
|
21
|
+
descriptor = 'streaming '
|
22
|
+
elsif flag == '--userstream' || flag == '-U'
|
23
|
+
descriptor = 'userstream '
|
24
|
+
end
|
25
|
+
puts "scaffolding a #{descriptor}twitter bot named #{bot_name}!"
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_directories! bot_name
|
11
29
|
Dir.mkdir bot_name
|
12
|
-
|
13
|
-
puts "mkdir #{dirname}"
|
30
|
+
puts "mkdir #{bot_name}/"
|
14
31
|
folders.each do |folder|
|
15
|
-
|
16
|
-
|
32
|
+
folder_path = File.join bot_name, folder
|
33
|
+
Dir.mkdir folder_path
|
34
|
+
puts "mkdir #{folder_path}/"
|
17
35
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
def write_files! bot_name, flag
|
39
|
+
(files bot_name, flag).each do |(file_name, contents)|
|
40
|
+
file_path = File.join bot_name, file_name
|
41
|
+
puts "touch #{file_path}"
|
42
|
+
File.open file_path, 'w' do |f|
|
21
43
|
f.write contents
|
22
44
|
end
|
23
45
|
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def exit_message bot_name
|
24
49
|
puts 'done generating! your turn now!'
|
25
50
|
puts "$ cd #{bot_name}"
|
26
51
|
puts '$ bundle install'
|
@@ -29,13 +54,13 @@ class TwitterBotGenerator
|
|
29
54
|
puts 'HAVE FUN BE SAFE PLAY NICE'
|
30
55
|
end
|
31
56
|
|
32
|
-
|
57
|
+
private
|
33
58
|
|
34
59
|
def folders
|
35
60
|
%w(lib src test)
|
36
61
|
end
|
37
62
|
|
38
|
-
def files bot_name
|
63
|
+
def files bot_name, flag
|
39
64
|
varz = grab_a_binding_for bot_name
|
40
65
|
{
|
41
66
|
'bot.rb' => (render_code 'bot.rb', varz),
|
@@ -48,7 +73,19 @@ class TwitterBotGenerator
|
|
48
73
|
"test/#{bot_name}_test.rb" => (render_code 'test/test_bot_test.rb', varz),
|
49
74
|
"src/#{bot_name}.rb" => (render_code 'src/test_bot.rb', varz),
|
50
75
|
'lib/greetings.txt' => (render_code 'lib/greetings.txt', varz)
|
51
|
-
}
|
76
|
+
}.tap do |filz|
|
77
|
+
if flag == '--streaming' || flag == '-S'
|
78
|
+
filz['bot.rb'] = (render_code 'streaming-bot.rb', varz)
|
79
|
+
filz['spec.rb'] = (render_code 'streaming-spec.rb', varz)
|
80
|
+
filz["test/#{bot_name}_test.rb"] = (render_code 'test/streaming-test_bot_test.rb', varz)
|
81
|
+
filz["src/#{bot_name}.rb"] = (render_code 'src/streaming-test_bot.rb', varz)
|
82
|
+
elsif flag == '--userstream' || flag == '-U'
|
83
|
+
filz['bot.rb'] = (render_code 'userstream-bot.rb', varz)
|
84
|
+
filz['spec.rb'] = (render_code 'userstream-spec.rb', varz)
|
85
|
+
filz["test/#{bot_name}_test.rb"] = (render_code 'test/userstream-test_bot_test.rb', varz)
|
86
|
+
filz["src/#{bot_name}.rb"] = (render_code 'src/userstream-test_bot.rb', varz)
|
87
|
+
end
|
88
|
+
end
|
52
89
|
end
|
53
90
|
|
54
91
|
def grab_a_binding_for bot_name
|
@@ -60,8 +97,6 @@ class TwitterBotGenerator
|
|
60
97
|
(get_template file_name).result varz
|
61
98
|
end
|
62
99
|
|
63
|
-
private
|
64
|
-
|
65
100
|
def camelize str
|
66
101
|
((str.split '_').map &:capitalize).join
|
67
102
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
bot: ruby bot.rb
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# such_test_bot
|
2
|
+
A Twitter Bot
|
3
|
+
|
4
|
+
## Development
|
5
|
+
|
6
|
+
> bundle install
|
7
|
+
> ruby test.rb
|
8
|
+
> ruby spec.rb
|
9
|
+
|
10
|
+
## Deployment (heroku)
|
11
|
+
|
12
|
+
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
13
|
+
|
14
|
+
0. You probably need git and the heroku toolbet installed and also a heroku account.
|
15
|
+
0. Make a twitter account for your bot. Give it a photo and header and some biographical information
|
16
|
+
0. Go into settings > mobile and add a cell phone number that you can send a text from.
|
17
|
+
not all carriers will work :(
|
18
|
+
without a mobile number, twitter won't let you get the api keys you need to deploy
|
19
|
+
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
20
|
+
0. go to apps.twitter.com and sign in again
|
21
|
+
0. click create a new app
|
22
|
+
0. fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
23
|
+
0. once your app is created, click "modify app permissions" and set the app to read and write
|
24
|
+
0. wait a lil bit to get access tokens
|
25
|
+
0. SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
26
|
+
0. From the command line:
|
27
|
+
|
28
|
+
```
|
29
|
+
heroku create
|
30
|
+
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
31
|
+
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
32
|
+
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
33
|
+
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
34
|
+
```
|
35
|
+
|
36
|
+
0. go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
37
|
+
0. THE MAIN EVENT:
|
38
|
+
|
39
|
+
```
|
40
|
+
git push heroku master
|
41
|
+
heroku ps:scale bot=1
|
42
|
+
```
|
43
|
+
|
44
|
+
0. go to your bot's page and you should see it's first tweet! Or something?
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'src/such_test_bot.rb'
|
2
|
+
require 'twitter'
|
3
|
+
twitter = Twitter::REST::Client.new do |config|
|
4
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
5
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
6
|
+
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
|
7
|
+
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
|
8
|
+
end
|
9
|
+
|
10
|
+
loop do
|
11
|
+
begin
|
12
|
+
twitter.update SuchTestBot.generate
|
13
|
+
ensure
|
14
|
+
sleep 10800 + (rand 5400)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class SuchTestBot
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def generate
|
6
|
+
greetings.sample
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def greetings
|
12
|
+
@greetings ||= load_txt_file 'greetings.txt'
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def load_txt_file file_name
|
18
|
+
home_sweet_home = File.expand_path File.dirname __FILE__
|
19
|
+
ultimate_pathway = File.join home_sweet_home, '..', 'lib', file_name
|
20
|
+
(File.readlines ultimate_pathway).map &:strip
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
4
|
+
require_relative '../src/such_test_bot.rb'
|
5
|
+
|
6
|
+
class TestSuchTestBot < MiniTest::Test
|
7
|
+
|
8
|
+
def test_generate_returns_hello_world
|
9
|
+
assert_match /Hello/, SuchTestBot.generate
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_hides_greetings
|
13
|
+
refute_respond_to SuchTestBot, :greetings
|
14
|
+
assert_instance_of String, SuchTestBot.send(:greetings)[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_hides_io_metal
|
18
|
+
refute_respond_to SuchTestBot, :load_txt_file
|
19
|
+
assert_equal 3, SuchTestBot.send(:load_txt_file, 'greetings.txt').length
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
wipe_such_test_bot!
|
4
|
+
TwitterBotGenerator.generate 'such_test_bot'
|
5
|
+
|
6
|
+
puts 'Running the test suite for the generated DEFAULT bot'
|
7
|
+
Dir.chdir('such_test_bot')
|
8
|
+
puts load '../such_test_bot/test/such_test_bot_test.rb'
|
9
|
+
Dir.chdir('..')
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
wipe_such_test_bot!
|
4
|
+
TwitterBotGenerator.generate 'such_test_bot', '--streaming'
|
5
|
+
|
6
|
+
puts 'Running the test suite for the generated STREAMING bot'
|
7
|
+
Dir.chdir('such_test_bot')
|
8
|
+
puts load '../such_test_bot/test/such_test_bot_test.rb'
|
9
|
+
Dir.chdir('..')
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
wipe_such_test_bot!
|
4
|
+
TwitterBotGenerator.generate 'such_test_bot', '--userstream'
|
5
|
+
|
6
|
+
puts 'Running the test suite for the generated USERSTREAM bot'
|
7
|
+
Dir.chdir('such_test_bot')
|
8
|
+
puts load '../such_test_bot/test/such_test_bot_test.rb'
|
9
|
+
Dir.chdir('..')
|
@@ -1,5 +1,10 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
+
wipe_such_test_bot!
|
4
|
+
TwitterBotGenerator.generate 'such_test_bot'
|
5
|
+
|
6
|
+
puts 'testing the scaffolding'
|
7
|
+
|
3
8
|
class TestTwitterBotGenerator < MiniTest::Test
|
4
9
|
|
5
10
|
def test_it_creates_an_app_directory
|
@@ -27,7 +32,7 @@ class TestTwitterBotGenerator < MiniTest::Test
|
|
27
32
|
def test_it_creates_a_gitignore
|
28
33
|
assert_equal true, (File.exists? './such_test_bot/.gitignore')
|
29
34
|
assert_match /.DS_Store/, (File.read './such_test_bot/.gitignore')
|
30
|
-
assert_match
|
35
|
+
assert_match /\*.todo/, (File.read './such_test_bot/.gitignore')
|
31
36
|
end
|
32
37
|
|
33
38
|
def test_it_creates_a_gemfile
|
data/test/test_helper.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
-
require 'minitest/autorun'
|
3
2
|
require 'minitest/pride'
|
4
3
|
require 'coveralls'
|
5
4
|
Coveralls.wear!
|
6
5
|
|
7
6
|
require_relative "../lib/twitter_bot_generator.rb"
|
8
7
|
|
9
|
-
|
10
|
-
TwitterBotGenerator.generate 'such_test_bot'
|
11
|
-
|
12
|
-
Minitest.after_run do
|
8
|
+
def wipe_such_test_bot!
|
13
9
|
['./such_test_bot/Gemfile',
|
14
10
|
'./such_test_bot/README.md',
|
15
11
|
'./such_test_bot/test.rb',
|
@@ -19,10 +15,17 @@ Minitest.after_run do
|
|
19
15
|
'./such_test_bot/test/such_test_bot_test.rb',
|
20
16
|
'./such_test_bot/lib/greetings.txt',
|
21
17
|
'./such_test_bot/src/such_test_bot.rb',
|
22
|
-
'./such_test_bot/.gitignore'].each { |file| File.unlink file }
|
18
|
+
'./such_test_bot/.gitignore'].each { |file| File.unlink file if File.exists? file }
|
23
19
|
|
24
20
|
['./such_test_bot/lib',
|
25
21
|
'./such_test_bot/src',
|
26
22
|
'./such_test_bot/test',
|
27
|
-
'./such_test_bot'].each { |dir| Dir.rmdir dir }
|
23
|
+
'./such_test_bot'].each { |dir| Dir.rmdir dir if Dir.exists? dir}
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
Minitest.after_run do
|
28
|
+
# leave behind a default scaffold ALWAYS
|
29
|
+
wipe_such_test_bot!
|
30
|
+
TwitterBotGenerator.generate 'such_test_bot'
|
28
31
|
end
|
@@ -9,7 +9,23 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Cole Willsea"]
|
10
10
|
spec.email = ["coleww@gmail.com"]
|
11
11
|
spec.summary = %q{Generates a twitter bot template from command line.}
|
12
|
-
spec.description =
|
12
|
+
spec.description = <<-EOF
|
13
|
+
Scaffolds a new boilerplate twitter bot project from the command line.
|
14
|
+
By default will create a bot that tweets a "hello world" type greeting once every 3-4.5 hours
|
15
|
+
Can also pass a --streaming flag to create a bot that listens to the "gardenhose"
|
16
|
+
Or a --userstream flag for a bot that listens for tweets @ it.
|
17
|
+
To use:
|
18
|
+
|
19
|
+
$ gem install twitter_bot_generator
|
20
|
+
$ twitter_bot_generator --help
|
21
|
+
$ twitter_bot_generator my_new_bot
|
22
|
+
$ cd my_new_bot
|
23
|
+
$ bundle install
|
24
|
+
$ ruby test.rb
|
25
|
+
$ ruby spec.rb
|
26
|
+
|
27
|
+
etc.
|
28
|
+
EOF
|
13
29
|
spec.homepage = "https://github.com/coleww/twitter_bot_generator"
|
14
30
|
spec.license = "MIT"
|
15
31
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_bot_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cole Willsea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,22 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: |2
|
84
|
+
Scaffolds a new boilerplate twitter bot project from the command line.
|
85
|
+
By default will create a bot that tweets a "hello world" type greeting once every 3-4.5 hours
|
86
|
+
Can also pass a --streaming flag to create a bot that listens to the "gardenhose"
|
87
|
+
Or a --userstream flag for a bot that listens for tweets @ it.
|
88
|
+
To use:
|
89
|
+
|
90
|
+
$ gem install twitter_bot_generator
|
91
|
+
$ twitter_bot_generator --help
|
92
|
+
$ twitter_bot_generator my_new_bot
|
93
|
+
$ cd my_new_bot
|
94
|
+
$ bundle install
|
95
|
+
$ ruby test.rb
|
96
|
+
$ ruby spec.rb
|
97
|
+
|
98
|
+
etc.
|
84
99
|
email:
|
85
100
|
- coleww@gmail.com
|
86
101
|
executables:
|
@@ -104,11 +119,31 @@ files:
|
|
104
119
|
- lib/twitter_bot_generator/templates/bot.rb.erb
|
105
120
|
- lib/twitter_bot_generator/templates/lib/greetings.txt.erb
|
106
121
|
- lib/twitter_bot_generator/templates/spec.rb.erb
|
122
|
+
- lib/twitter_bot_generator/templates/src/streaming-test_bot.rb.erb
|
107
123
|
- lib/twitter_bot_generator/templates/src/test_bot.rb.erb
|
124
|
+
- lib/twitter_bot_generator/templates/src/userstream-test_bot.rb.erb
|
125
|
+
- lib/twitter_bot_generator/templates/streaming-bot.rb.erb
|
126
|
+
- lib/twitter_bot_generator/templates/streaming-spec.rb.erb
|
108
127
|
- lib/twitter_bot_generator/templates/test.rb.erb
|
128
|
+
- lib/twitter_bot_generator/templates/test/streaming-test_bot_test.rb.erb
|
109
129
|
- lib/twitter_bot_generator/templates/test/test_bot_test.rb.erb
|
130
|
+
- lib/twitter_bot_generator/templates/test/userstream-test_bot_test.rb.erb
|
131
|
+
- lib/twitter_bot_generator/templates/userstream-bot.rb.erb
|
132
|
+
- lib/twitter_bot_generator/templates/userstream-spec.rb.erb
|
110
133
|
- lib/twitter_bot_generator/version.rb
|
111
|
-
-
|
134
|
+
- such_test_bot/.gitignore
|
135
|
+
- such_test_bot/Gemfile
|
136
|
+
- such_test_bot/Procfile
|
137
|
+
- such_test_bot/README.md
|
138
|
+
- such_test_bot/bot.rb
|
139
|
+
- such_test_bot/lib/greetings.txt
|
140
|
+
- such_test_bot/spec.rb
|
141
|
+
- such_test_bot/src/such_test_bot.rb
|
142
|
+
- such_test_bot/test.rb
|
143
|
+
- such_test_bot/test/such_test_bot_test.rb
|
144
|
+
- test/generated_default_bot.rb
|
145
|
+
- test/generated_streaming_bot.rb
|
146
|
+
- test/generated_userstream_bot.rb
|
112
147
|
- test/scaffold_generator_test.rb
|
113
148
|
- test/test_helper.rb
|
114
149
|
- twitter_bot_generator.gemspec
|
@@ -137,6 +172,8 @@ signing_key:
|
|
137
172
|
specification_version: 4
|
138
173
|
summary: Generates a twitter bot template from command line.
|
139
174
|
test_files:
|
140
|
-
- test/
|
175
|
+
- test/generated_default_bot.rb
|
176
|
+
- test/generated_streaming_bot.rb
|
177
|
+
- test/generated_userstream_bot.rb
|
141
178
|
- test/scaffold_generator_test.rb
|
142
179
|
- test/test_helper.rb
|