Your Own @Horse_ebooks

Around 2013, @horse_ebooks became a very iconic staple in the history of Twitter. I’m gonna teach you how to make your own.

Relevant XKCD

First things first hop on a machine running \*NIX (OS X, Linux, etc)

Also make sure you have Git installed.

mispy has my favourite ebooks code so I suggest cloning their example. It works fantastically.

git clone nulljosh_ebooks
cd nulljosh_ebooks/

Then you’ll want to install all of the dependencies (which are in Ruby)

sudo gem install bundler
bundle install

> This `sudo` trick is a hack and I would suggest against it for them most part. The only reason I’m adding it here is I assume most of you will not touch Ruby again on your machines. If you’re planning on using Ruby in the future, or if you have before, set up a Ruby environment and fix gem permissions, then run this command without root privileges as a less hack-ey method. `sudo` provides root access, which gives you complete God-like control of your machine. You should always be careful with any command you run with it. In this particular case we’re simply installing a few gems/libraries, but always make sure you know what you’re running with it.

Once the dependencies (gems) are installed, npm will be the next thing you’ll need installed.

With npm installed you can install a module Kirby made. You may have to kill Terminal first before running this (remember to `cd` back into your project.)

sudo npm install -g twauth

> Again, the `sudo` command is a hack. Same reasons apply here. In this case we’re installing a module that allows us to authenticate OAuth keys with Twitter.

We’ll use twauth to essentially bypass Twitter’s phone verification, which they have in place to prevent users from abusing apps.

Now would be a good time to create a Twitter account for your bot. Make sure the email is confirmed. Then sign up for a Heroku account, which you’ll be using to deploy your bot to — unless you have your own server in which you can do that yourself. Once you have a Heroku account, download/install the Heroku Toolbelt. Once that’s done, login to Heroku through Terminal:

heroku login

Now pertaining to what I mentioned earlier about bypassing Twitter’s phone authorization, the easiest way to bypass this is to use already generated public and private/secret keys. Tweetbot’s keys leaked a while ago, so let’s just use theirs.

twauth — key=v8xVBZlXBp2AJoWI3VjDjzDkC — secret=Wpoom4N6tpTgfywzCt6y83gvZubbYoT0vL0V8FXzhyXA74218D

> I’m just gonna slap an “for educational purposes only” on here so I don’t get in trouble. I don’t think that’s gonna help me, though.

Your terminal will now provide you with a link to follow. Open it, sign in with your ebooks account, and you should run into an error message. This is expected. Check the URL, it should look something like this.

Copy the value of `&oauth_verifier`. In this case `4Wg5gzPhxcWrtfgee6Dgg8GwPgahhCRD`. Go back to your terminal and paste this in as your “pin number”. Hit enter and your terminal should respond with two OAuth keys — one public, one private. Keep this terminal window open or copy the keys down — We’ll be using them in a minute

Open `bots.rb`

Flip back to Terminal and make sure you’re still in your ebooks folder. Now you can generate an archive from your tweets.

export username=your_original_twitter_username
ebooks archive $username corpus/$username.json
ebooks consume corpus/$username.json

Now comes the unveil — we want to test that the bot is working alright. We can use Heroku’s `foreman` command for that:

foreman start

Try tweeting your bot now, or maybe follow it. Everything should be working.

We’re almost finished now — we just want to push our bot to Heroku’s servers. First, initialize the git repository, then add all of your work, and commit it:

git init
git add -A
git commit -m “Initial Commit”

Heroku works with git quite nicely so you just need to create it, give it Heroku’s remote, and push it. Also, make sure your Heroku server has an instance of the app.

heroku create
heroku ps:scale worker=1
git push heroku master

Try tweeting at your ebooks now, see if things are working. Hopefully they are– if they’re not, feel free to tweet me angry things (or ask for help) at @nulljosh.



Functioning Node Dev

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store