I first joined Twitter in 2009 because I heard someone reference it and was curious what it was. I didn't use it much then, but I do now to get news and updates on things I'm interested in. I was working with python at the time, and wanted to create a bot using Twitter's API. I've seen plenty of stories on social media about athletes and celebrities having old, inappropriate tweets dug up from their past, so I thought why not make a bot that people can use to clear their Twitter history? It's painstakingly slow to manually delete tweets, especially if you've tweeted a lot over multiple years. So with my plan in mind, I started writing some code to make it happen.

2020

Python, API, Heroku, Twitter

Screenshot of my twitter profile where my bot runs each day

This is a super simple python bot that runs on Heroku. The logic is just retrieving a Twitter profile's tweet history, checking the creation date to see if it's existed for more than a year, make sure it's not a retweet, and then delete! I also added a check for if it's been liked by the profile, so if I want to save a tweet of mine for more than a year, I can just like my own tweet as a "don't delete this" flag that my bot will see.

Authorization and looping to find the tweets to delete

The hardest part of this project was getting Twitter to approve my developer application. After I was approved, I just had to throw in the authorization tokens and I could grab all the Tweets I wanted. I have worked with Python and Twitter before for a school project where we scrapped tweets for keywords, so this wasn't too challenging for me. The scheduling is ran using a Heroku worker process that starts at 4am each day.

Code for scheduling functionality

I don't have many tweets to delete these days, as I mostly read other users tweets and might retweet something occasionally. But this project was great practice for me and I was glad I learned how to use Twitter's API. You'll see in a more recent project I was able to use it again for another bot!

You may also like

Back to Top