“This is Tina.” http://redd.it/ctj32b #aww

How to make a Twitter cuteness bot.

The easy way and the hard way.

Kevin McElwee
Published in
2 min readAug 25, 2019

--

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 tweepy.

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.

reddit_says_aww.py flowchart

Uploading media to Twitter through the API can get complicated. For this reason, the bot only handles images and gifs, and not videos. 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. Also, since Reddit titles can exceed Twitter’s character limit, a function shortens the title and adds ellipses when necessar.

UPDATE: This bot used to rely on Heroku, but it has been migrated to GitHub Actions, a free alternative. More information is available here to set up a bot with one’s own configuration. There’s nothing special about r/aww here, so this bot can be configured to transfer posts from any subreddit.

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. 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.

--

--