I will be the first to admit it: I don't like socia media.
It's not that I do not enjoy the idea of staying connected with the ones that I love and having a way to keep up with their lives. In fact, the dream would be to use social media for just that.
The reason I do not like social media is because social media has more control over me than I have over it. There, I admitted it. Happy?
Call me overly-optimistic, but I still believe that I can still somehow make it work. However, to make it work for me is going to require some fine tuning.
Fine tuning for Facebook and Instagram meant deleting it. I did this six months ago. I am sure there will be a use case for the Facebook account down the track for business and advertising reasons, but applying Occam's razor to why I used both applications at moment was not for business purposes, ergo I gave it the flick.
As for Twitter, it can be a real negative Nancy, however I do get a number of really important notifications from there. What I want to do with Twitter is minimise the negativity and remove any trace of my history from the app where I can.
To start this process, I built a simple Twitter bot that runs on a cron job and will delete any tweet older than seven days from my profile.
In this tutorial, I will demonstrate the first part of deleting Tweets.
- Basic Nodejs understanding.
- Basic Typescript understanding.
- Read my post on Using the AWS CDK to invoke a Lambda function during a cron job. I will not cover the cron job part today in this tutorial.
- Your required credentials for Twit.
In a new folder of your choice, run the following:
Setting up Dotenv
If you followed the prerequisites, you will have your account keys.
Add the keys to the correct variable into
Setting up TypeScript, Nodemon.json and Package.json
tsconfig.json, we are going to tell it to target Node requirements. We are adding the
ES2020.Promise lib so we can make use of
Promise.allSettled, but you could leave it out if you want to use
Promise.all instead (not that any rejection will result in all rejecting if not
Add the following to the file:
nodemon.json, we are basically going to tell it is run
etsc when a file changes with the
package.json, add the following to the scripts key (the rest is omitted for brevity):
Creating our Twitter helper file
src/twitter/index.ts, add the following:
This post expects you to be able to understand the above, but the long and short of it is that we are using
dotenv to require the local variables from the
We then have two main functions
destroyMany that will get up to
n tweets from your account and then destroy all those tweets respectively.
Now it is time to write the main script that will make use of these functions.
Writing the main script
src/index.ts, add the following:
Here we are waiting to get the maximum tweet count (200) with out
getUserTimeline call, then iterating through the response data to figure out if the create date is older than a week. If it is, we are pushing it to a
tweetsToDelete array and then finally passing that array to
We log out the
manyDestroyed variable to see which requests were fulfilled and had the tweets deleted.
Running the script
To run the script mode, run
npm start (to run with
nodemon in watch mode). This will start Nodemon and if successful you will see your tweets older than 7 days beginning to delete!
If you've tweeted more than 200 times, you may need to run the script over again a few times until it is comes back with no more to delete!
This was a quick-fire post, but it was an overview of how I wrote a script to start deleting my tweets older than a week!
Moving on from here, I set up a cron job to run every day at midnight to re-check and delete any other tweets.
I am really hoping this gives inspires (I use the term loosely) to stop posting on Twitter and use it to consume. My next move with Twitter will be to add something that filters tweets on in my feed using some ML/AI.
Resources and Further Reading
Image credit: Patrick Perkins
- aws cdk
- aws lambda
Deploy a simple Python lambda function with the TypeScript AWS CDK to LocalStack.
Deploy a Kubernetes Fargate on EKS cluster using the AWS CDK.
Use the ECS patterns library to deploy a simple Fargate cluster to LocalStack.
- aws cdk
Use the TypeScript AWS CDK to deploy an S3 Bucket fronted by a CloudFront CDN and Route53 record.
1,200+ PEOPLE ALREADY JOINED ❤️️
Get fresh posts + news direct to your inbox.
No spam. We only send you relevant content.