Introducing @tinyraces

Written on May 9, 2018

TL;DR check out my new Twitter bot @tinyraces.

Last year — to the day — I announced my first Twitter bot, @year_left. Since releasing @year_left, I get delighted every time a tweet from the account shows up in my timeline. Like magic, a bot (more like a lambda function) runs a script and poof, it shows up on Twitter.

As much as I love building web applications, I really enjoy building Twitter bots and command line tools. This is because I don’t have to focus so much about the design but focus on the inner-workings of the code. They’re also very limited in scope, often doing just a single thing.

A few days ago, delighted by seeing @year_left tweet again on my timeline, I thought I’d create another bot. I wanted to go with something a little more whimsical. Looking over other bots like @tiny_star_field and @tiny_forests, I decided I wanted my next bot to use more emojis and be visually appealing.

I wanted to do something a little different from the other bots mentioned above, in that I wanted to make it a little more interactive with followers. Thinking about ideas, I thought about the annual state fair in my city. There’s this one exhibit where various farm animals like ducks and pigs race each other around a square track. It’s such a hoot and everyone who sees it really enjoy it.

So I decided I’d make a Twitter bot that would have emoji contenders race each other in intervals until there is a winner and it’s called @tinyraces.

@tinyraces features four races that occur throughout the day. Each race stars random contenders ranging from vehicles, animals and even the poop emoji. When each race starts, each leg of the race is tweeted in 6 minute intervals until a winner or winners are determined.

Each race should be threaded so it’s easy to catch a race happen from start to finish.

I enjoyed making @tinyraces but I admit, I ran into a lot of roadbumps that almost made me throw in the towel at times at the idea.

  • Graphically the races looked a little more complex when I first started, where once a contender won a race, they would “cross” the finish line. Instead, I ended up calling a race finished, when contenders reached the finish line.
  • At one point when the algorithm was in place to generate the different phases of the race, I had to refactor it so that I could persist each interval and tweet it. In doing my refactoring, I had introduced a bug where I wasn’t properly sanitizing data when picking up where the last race left off. In doing so it was introducing more characters to my lanes.
  • Discovering that emojis have a string length of 2 characters and determining the position of them in updating each lane.
  • The last issue which was the one which almost made me give up was setting up the cron job to run the script. I had forgotten that I had run into this issue before. The issue being the method in which I chose to persist my data for the race was using text files. Every time my cron job would run, the files would never get read or written to. Googling only surfaced my own StackOverflow question that I had asked the last time I ran into this issue. Unfortunately, that solution didn’t work. It wasn’t until I had found this StackOverflow thread that I realized the problem was that my read and write was setup relative to the script I was running. Upon updating the code to use absolute paths to the files to be read and written to, my bot started working as expected!

So today, I’m happy to announce @tinyraces, the Twitter bot that generates little races throughout the day. I hope you’ll give it a follow and more than anything I hope it delights your day.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share articles like this one in your inbox. Sign up for my newsletter.