I’m a tweet deleter. I do not think of Twitter as a great archive of knowledge but more a mere feed and notification system. It is basically an internet wide RSS feed, so no need to treat anything in it too preciously. Delete away everyone.
I’ve written a couple of one off scripts previously to mass delete and groom my feed, but I never really automated it, until now. I came across this post by Vicky Lai on how to automatically delete your Tweets using AWS Lambda, which she uses a Go program running on AWS to delete tweets.
I don’t really want to bother with AWS, but I do have a Raspberry Pi that is running all the time as a PiHole network device. It wouldn’t mind running a quick program every so often.; and Golang compiles to Pi, golden.
I modified Vicky’s program ephemeral to run outside of Lambda and added one flag to allow keeping tweets older than a specific date around. I like keeping my first tweet around.
You can configure ephemeral to delete all tweets older than a certain number of hours and also after a specific date. Mine is configured for tweets older than 72 hours but newer than 2016.
Binary downloads and source available at: github.com/mkaz/ephemeral
You will need to create a new Twitter application and generate API keys.
The program assumes the following environment variables are set, see env.sh.sample for an example:
TWITTER_CONSUMER_KEY TWITTER_CONSUMER_SECRET TWITTER_ACCESS_TOKEN TWITTER_ACCESS_TOKEN_SECRET MAX_TWEET_AGE TWEPOCH
MAX_TWEET_AGE expects a value of hours, such as:
TWEPOCH expects a date value in
- See releases in Github for binaries for Linux and Raspberry Pi.
env.shfile to set environment variables
--testflag to do a test run
$ source env.sh $ ephemeral --test
--test flag when you’re ready to delete away.
I run this program using cron on a scheduled time off a Raspberry Pi. Here is the cron entry which shows sourcing env.sh prior to running at 8am everyday. See my Unix Crontab post for more info using cron.
0 8 * * * . path/to/dir/env.sh; path/to/dir/ephemeral
The program is a standard golang program, so the build process is quite straight-forward. The great thing about golang is its ability to target multiple architectures. You can do a cross-compile build for Raspberry Pi using:
env GOOS=linux GOARCH=arm GOARM=5 go build
Thanks to Vicky for publishing her program which was based off Adam Drake’s Harold program. All of which use the Go client library for Twitter called Anaconda. So thanks all for the groundwork which makes this pretty easy.
To learn more about Golang, see my Working with Go tutorial.