How to make a Twitter cuteness bot.
The easy way and the hard way.
The “aww” subreddit is arguably the cuteness singularity of the internet. With more than 20 million members, usually tens of thousands of users judge the cuteness of every post. We can leverage Twitter and Reddit’s developer APIs to share the best content of r/aww to Twitter.
How it works.
Here’s the Twitter account @reddit_says_aww. And here is a link to the code. Naturally, I’ve removed the public and private keys for my Reddit and Twitter accounts, but if you apply for a developer account at both companies, they can generate authorization tokens for you. Reddit’s python wrapper is called
praw and Twitter’s python wrapper is called
The bot requests the top five posts on r/aww’s “hot” tab. If the content has not been tweeted before, then it properly formats the content and posts to Twitter. Here’s a flowchart that breaks down how the code functions.
Uploading media to Twitter through the API can get complicated. For this reason, the bot only handles images and gifs, not videos, at least for now. If the content is hosted on imgur or gfycat, then Twitter will automatically load a preview, so instead of uploading the media, we can simply post the link. Reddit’s video, however, is not supported in Twitter’s embed system, so the bot must miss some cute videos. There are many exceptions and if statements used to handle how different file formats are uploaded. Another exception to consider is the Twitter character limit. If Reddit titles exceed the twitter count, there’s a function to shorten the title and add ellipses.
I’m using Heroku as a place to host my bot online, but other options are available, including Digital Ocean. You’ll be hard-pressed to find a hosting service that is free. Heroku’s current rate is $7/month.
For Heroku specifically, you’ll need something called
Procfile as well as a
Procfile is just a single line that runs your app; mine simply says:
worker: python reddit_says_aww.py
More details can be found here.
Why simpler methods won’t work too well.
The IFTTT (If This Then That) platform has made it easy to create straightforward Twitter bots. For example, my Mindfulness Bot was incredibly simple to make. This is many times faster than the hard-coding approach (and free!). If you’re trying to make a similar bot, I would recommend to always start with IFTTT before trying to make a bot by hand. Because the bot had to ignore video and manage different file formats, however, IFTTT was ineffective at consistently posting material clearly. For this project it was not best suited. If you’re interested in replicating this bot on a text-based reddit, then IFTTT might be the right fit!