Automate deleting your tweets with a Raspberry Pi

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.

Ephemeral

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.

So 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 after 2016.

Binary downloads and source available at: github.com/mkaz/ephemeral

Usage

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: MAX_TWEET_AGE=72h

TWEPOCH expects a date value in YYYY-MM-DD format

Run

  1. See releases in Github for binaries for Linux and Raspberry Pi.
  2. Source env.sh file to set environment variables
  3. Use –test flag to do a test run
$ source env.sh
$ ephemeral --test

Remove --test flag when you’re ready to delete away.

Automate

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.

0 8 * * * . path/to/dir/env.sh; path/to/dir/ephemeral

Build

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

Kudos

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.