visit
From now on, my tweets are ephemeral. Here’s why I’m deleting all my old tweets and the AWS Lambda function that does it for free.
The assumption made of things written in social media and on Twitter specifically is a very different assumption than you might make about someone’s notepad scribble from last week. I’m not endeavoring to speculate why — I’ve just seen enough cases of someone getting publicly flogged for something they posted years ago to know that it does happen. This is weird. If you wouldn’t assume that a notepad scribble from last week or a crayon drawing from decades ago reflects the essence of who someone is now, why would you assume that an old tweet does?
You are not the same person you were last month — you’ve seen things, read things, understood and learned things that have, in some small way, changed you. While a person may have the same sense of self and identity through most of their life, even this grows and changes over the years. We change our opinions, our desires, our habits. We are not stagnant beings, and we should not let ourselves be represented as such, however unintentionally.The code that makes up ephemeral is written in Go. AWS Lambda creates an environment for each Lambda function, so ephemeral utilizes environment variables for your private Twitter API keys and the maximum age of the tweets you want to keep, represented in hours, like 72h
.
var ( consumerKey = getenv("TWITTER_CONSUMER_KEY") consumerSecret = getenv("TWITTER_CONSUMER_SECRET") accessToken = getenv("TWITTER_ACCESS_TOKEN") accessTokenSecret = getenv("TWITTER_ACCESS_TOKEN_SECRET") maxTweetAge = getenv("MAX_TWEET_AGE") logger = log.New())
func getenv(name string) string { v := os.Getenv(name) if v == "" { panic("missing required environment variable " + name) } return v}
The program uses the library. It fetches your timeline up to the Twitter API’s limit of 200 tweets per request, then compares each tweet’s date of creation to your MAX_TWEET_AGE
variable to decide whether it’s old enough to be deleted. After deleting all the expired tweets, the Lambda function terminates.
func deleteFromTimeline(api *anaconda.TwitterApi, ageLimit time.Duration) { timeline, err := getTimeline(api)
if err != nil { log.Error("Could not get timeline") } for _, t := range timeline { createdTime, err := t.CreatedAtTime() if err != nil { log.Error("Couldn't parse time ", err) } else { if time.Since(createdTime) > ageLimit { _, err := api.DeleteTweet(t.Id, true) log.Info("DELETED: Age - ", time.Since(createdTime).Round(1*time.Minute), " - ", t.Text) if err != nil { log.Error("Failed to delete! ", err) } } } } log.Info("No more tweets to delete.")
}
Read the full code .
For a use case like this, AWS Lambda has a free tier that costs nothing. If you’re any level of developer, it’s an extremely useful tool to become familiar with. For a full walkthrough with screenshots of how to set up a Lambda function that tweets for you, you can read . The set up for ephemeral is the same, it just has an opposite function. :)
I forked ephemeral from Adam Drake’s , a Twitter tool that has many useful functions beyond keeping your timeline trimmed. If you have more than 200 tweets to delete at first pass, please use Harold to do that first. You can run Harold with the deletetimeline
flag from your terminal.
I use it as a way to keep tabs on what’s happening right now. I use it to comment on, joke about, and commiserate with things tweeted by the people I follow right now. By keeping my timeline restricted to only the most recent few days, I feel like I’m using Twitter more like it was meant to be used: a way to join the conversation and see what’s happening in the world right now — instead of just another place to amass more “stuff.”
Thanks for reading! If you’d like to hear more about how I make my life better with tech, you can follow me here and on Twitter . For coding concepts explained with poorly-drawn doodles of food (and syntax highlighting!) go to . I hope you have a really great day. :)