What happened to my twitter account?

If you are any of the 500 followers(yep that’s right, 500) in my twitter account, you would see some unusual activity in my account over the past few days. I have been tweeting a lot lately(precisely one tweet every ten minutes) and not replying to any of your replies or messages. Yeah, I put a bot.

Bots are cool. Bots automate. With growing onset of social media reputation I got freaked out my social media updates weren’t enough. So I decided instead of thinking of awesome new things to tweet about, I would let a bot think and tweet instead. It’s based on Markov chain and uses data from three other twitter profiles, one of which is my own.

Basically I followed this guide. You need an account at Heroku.com. It was all pretty easy to setup. However, I had to open up the terminal, navigate to the directory and run the code every time I wanted to generate a tweet. It wasn’t very automate-ey. I could use the scheduler add-on they provide on heroku site, but for that I had to put in my credit-card information(I don’t own a credit card). I had to think of something else.

So I used this tool called crontab in Linux. Running the command crontab -e yielded a file where it asked me to put the command I want to run in all a single line, along with the scheduled time and date.

Searching around the web, I found some tricks to use with the scheduler. Typing something like * * * * * would run the command every one minute and */10 * * * * would run it every ten minutes. Perfect.

The next thing I did was create a script file like tweet.sh and put it up in a current user accessible directory, like ~/workspace/shellME/tweet.sh. I made the script executable using chmod and then pointed its location on the crontab file. In tweet.sh, I wrote something like this :

cd ~/workspace/gitME/heroku_ebooks-master/ && heroku run worker

I could have written this inside the crontab file but this felt more elegant.

Finally, I sat back and waited with twitter site open in my browser, hitting refresh over and over. Finally, a tweet appeared. And then another one after ten minutes. And then another one next ten minutes. I was a happy man.

Note: Sometimes the Markov chain produces sentences longer than twitter limit, in which case the code just rejects those sentences and you have to wait another ten minutes, or any number of minutes you have set in your crontab file.