How to make a Twitter cuteness bot.
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.
UPDATE: This bot used to rely on Heroku, but it has now migrated to GitHub Actions, a free alternative. More information is available here to set up a bot with one’s own configuration. This allows for anyone to quickly deploy their own Reddit-to-Twitter bot without ever having to leave GitHub!
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!
Questions? Comments? Puppy photos? Contact me and see more projects on my website.