-
Download the code.
-
Register the application on this Twitter developer page.
-
Copy
config-sample.py
toconfig.py
and edit the necessary variables. This includes the auth tokens that you will obtain from the page above and the number of tweets you want to have at any given point in time. -
It turns out it is very tricky to obtain more than 3200 tweets for a given user. So, in order to batch-delete everything from the beginning, we are going to download the very handy Twitter archive. Go to your settings page and click on Your Twitter archive. Follow the instructions, download the
.zip
file and then copy thetweets.csv
file to the folder containing the code. -
Run
$ python delete_from_archive.py
. This will delete all your tweets since the beginning of time and will leave only the most recentn_keep
alive (you set this up in yourconfig.py
file). -
Every day, or hour, or whatever works for you, run
delete_tweets.py
. This will trim your timeline to the desired size.
And that's it. As long as you keep running the script from point 6, everything will be kept clean and tidy. It should be very easy to modify the code so that, instead of keeping the last N tweets, it keeps the ones from the last D days. I have no time to do this, but if you feel so inclined just take the code and help yourself.
The usual caveats apply: read the code and make sure you understand what it's doing, please do some tests before running it unattended, all under your responsibility, this might break your coffee machine, blah, blah.
Inspired by the code in this blog post.