Skip to content

Instantly share code, notes, and snippets.

@trepmal
Forked from apsun/delet_tweets.md
Last active September 24, 2023 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trepmal/97f5caa825d62c12e92a5fa7feea961b to your computer and use it in GitHub Desktop.
Save trepmal/97f5caa825d62c12e92a5fa7feea961b to your computer and use it in GitHub Desktop.
Delete your old tweets with this disgusting bash script

100% free. Runs completely locally on your machine. Bypasses the 3200 tweet limit. May require some eye bleach for the script. Here's how to use it:

  1. Go to settings -> account -> your Twitter data and request a download. This may take a few hours. You'll get an email with a link to download a zip file. Extract the zip file and navigate to the data directory.

  2. Go to Twitter in a web browser and find any Tweet you want to delete. We're going to use it to extract your authentication credentials for the next step. Open developer tools, delete the tweet, and find the request to https://twitter.com/i/api/graphql/.../DeleteTweet. Right click it and copy it as cURL.

  3. Save delet_tweets.sh into your data directory. Open it in a text editor, and paste the command you got from the previous step where it says YOUR_CURL_COMMAND_HERE. Replace the id parameter for --data with $tweet_id (make sure to adjust quoting accordingly). Add --compressed as well to tell curl to un-gzip the response. I also recommend adding -s

  4. Let 'er rip. It will probably take a while (for me, somewhere around 10-20k tweets an hour), so leave it running in the background.

#!/bin/bash
set -euo pipefail
# DELETE_AFTER="2012-07-01 0:00"
# DELETE_BEFORE="2016-07-02 0:00"
echo "deleting everything after ${DELETE_AFTER} = $(gdate --date "$DELETE_AFTER" +%s)"
echo "deleting everything before ${DELETE_BEFORE} = $(gdate --date "$DELETE_BEFORE" +%s)"
cat tweet.js \
| sed '1 s/window.YTD.tweet.part0 = //' \
| jq -r '.[] | [.tweet.id, (.tweet.created_at | strptime("%a %b %d %H:%M:%S %z %Y") | mktime)] | @tsv' \
| sort -k2 -n \
| awk -v d="$(gdate --date "$DELETE_AFTER" +%s)" '$2 > d' \
| awk -v d="$(gdate --date "$DELETE_BEFORE" +%s)" '$2 < d' \
| awk '{ print $1 }' \
| while read tweet_id; do
echo -n $tweet_id ": ";
CURL_COMMAND_HERE
echo '';
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment