Making a twitter bot

3 01 2015

Met with George and Marie at the London Hackspace to make twitter bots.

Started out by looking at hosting the bot, first port of call https://www.heroku.com

Even a simple _ebooks type bot needs to be hosted somewhere

a static IP connected constantly yo the internet

chose ruby from the options and followed the instructions to install ruby gem and bundler

i already had ruby and gem installed, we checked by opening terminal and searching for versions installing bundler was a bit tricker as I ruby and gem were install on my admin user not my day to day user (this is probably inaccurate) but I could get it to install it by typing sudo user (super user do) kinda tricking it into thinking I was the admin (which I am, just not from where i was accessing the terminal)

ERROR:  While executing gem … (Gem::FilePermissionError)

    You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

users-mbp-3:~ user$ sudo gem install bundler

installed the heroku toolbelt (by downlaoding and typing into terminal) which installed git. also need xcode which i already had

follwed instructions in th tutorial to install a demo app. typed into terminal to get to a specific folder

users-mbp-3:ruby-getting-started user$ open . 

^ is folder name              ^ is a neat ay to open the folder in the finder

opened gemfile in sublime 2 to see what gems the app will be using. The bundler sorts out actually getting all the gems – this is just a shopping list for it.

ls shows the same info in less detail in the terminal

ls -al shows more info in terminal

in this folder, I typed

 heroku create

to ‘create’ the app then uploaded it from my spanking new local git repository to heroku with

git push heroku master
 heroku ps:scale web=1

tell the server you want to run one instance of this app – scaled up from zero which is basically the difference between existing or not. (this is just the terminal version of doing the same thing in the pretty dashboard sliders on the heroku website)

Now I’ve got some free hosting, it’s time to make the twitter bot app. Then we stopped following the tutorial and moved on to making the app I’ll be pushing to heroku for real.

We start out looking at

http://blog.boodoo.co/how-to-make-an-_ebooks/

went to git hub repository and copied it into the terminal using

sudo gem install twitter_ebooks

clone git https://github.com/mispy/twitter_ebooks.git

this created a folder local to my machine that had bots.rb in it this is the bot that I can edit to make my own bot.

I’d already downloaded my twitter archive and created a twitter account called minkbot.

I followed the instructions on http://blog.boodoo.co/how-to-make-an-_ebooks/

For step 5. I needed to use an account that had a phone number attached so instead of using the new @m1nkbot account I used my main twitter account.

We used https://github.com/twitter/twurl to transfer the permissions over

in terminal

sudo gem install twurl

then following instructions on github https://github.com/twitter/twurl

I used two browsers one with my ‘normal’ account in and the other with the bot in.

In the ‘normal’ account’s browser I went to permissions and got the key code and secret code – these replace the [key] and [secret] in the code below in terminal

twurl authorize --consumer-key [key]       \
                    --consumer-secret [secret]

This gave me a URL which I opened in the bot’s browser and got a PIN that I put back into terminal.

Looked in users-mbp-3:minkbot user$ cat ~/.twurlrc to find my tokens and keys

took the tweets.csv file from my twitter archive and put it in the corpus folder in the bot

Back to http://blog.boodoo.co/how-to-make-an-_ebooks/ and follow the steps in 6 & 7.

back to https://github.com/mispy/twitter_ebooks

In sublime text 2 I edit in the key and secret from the permissions. and the tokens from the cat search.

There is an example bot here https://github.com/mispy/ebooks_example/blob/master/bots.rb

logged back in to heroku to upload the real app.

https://dashboard.heroku.com/apps/minkbot/code/heroku-git

If I ever edit this thing and make something new that I want to upload it to github, then I’ll need to create a new repository that hides my secret keys in an env

needs a gemfile.lock so used bundler to install the gemfile.lock in the minkbot local git repository in terminal.

now to edit bots.rb to try and make it do something more interesting! 😀

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: