From 5f51bec8f2ee5a770035b74166e8cf4cc3ce44e2 Mon Sep 17 00:00:00 2001 From: Sentello <44606412+Sentello@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:28:27 +0300 Subject: [PATCH 1/2] Create de-x-replies.py --- de-x-replies.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 de-x-replies.py diff --git a/de-x-replies.py b/de-x-replies.py new file mode 100644 index 0000000..f041854 --- /dev/null +++ b/de-x-replies.py @@ -0,0 +1,81 @@ +## +# de-x-replies.py -- delete all your replies w/o API access +# Copyright 2023 Thorsten Schroeder +# +# Published under 2-Clause BSD License (https://opensource.org/license/bsd-2-clause/) +# +# Please see README.md for more information +## + +import sys +import json +import requests + +def get_reply_ids(json_data): + + result = [] + data = json.loads(json_data) + + for d in data: + # Check if the tweet is a reply (in_reply_to_status_id_str is not null) + if d['tweet'].get('in_reply_to_status_id_str') is not None: + result.append(d['tweet']['id_str']) + + return result + +def parse_req_headers(request_file): + + sess = {} + + with open(request_file) as f: + line = f.readline() + while line: + try: + k, v = line.split(':', 1) + val = v.lstrip().rstrip() + sess[k] = val + except: + # ignore empty lines + pass + + line = f.readline() + + return sess + +def main(ac, av): + + if(ac != 3): + print(f"[!] usage: {av[0]} ") + return + + f = open(av[1], encoding='UTF-8') + raw = f.read() + f.close() + + # skip data until first '[' + i = raw.find('[') + reply_ids = get_reply_ids(raw[i:]) + + session = parse_req_headers(av[2]) + + for i in reply_ids: + delete_tweet(session, i) + # maybe add some random sleep here to prevent future rate-limiting + +def delete_tweet(session, tweet_id): + + print(f"[*] delete tweet-id {tweet_id}") + delete_url = "https://twitter.com/i/api/graphql/VaenaVgh5q5ih7kvyVjgtg/DeleteTweet" + data = {"variables":{"tweet_id":tweet_id,"dark_request":False},"queryId":"VaenaVgh5q5ih7kvyVjgtg"} + + # set or re-set correct content-type header + session["content-type"] = 'application/json' + r = requests.post(delete_url, data=json.dumps(data), headers=session) + print(r.status_code, r.reason) + print(r.text[:500] + '...') + + return + +if __name__ == '__main__': + + main(len(sys.argv), sys.argv) From 17abc7abb88804a435600574718d9bd20ce4b962 Mon Sep 17 00:00:00 2001 From: Sentello <44606412+Sentello@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:29:54 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 706ef05..9da3b7e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ +# de-x-replies.py + +**de-x-replies.py** is a Python script designed to delete all of your replies on Twitter without requiring access to the official Twitter API. The script leverages session headers from an authenticated Twitter session to delete only the replies from your tweet history, leaving your original tweets untouched. + +## Features + +- **Delete Replies Only**: This script identifies and deletes only replies, based on the `in_reply_to_status_id_str` field in Twitter's tweet data. +- **No Twitter API Required**: The script works by using session request headers, so no need for API keys or tokens. +- **Simple and Automated**: Provide the script with a JSON file of your tweet data and a file with request headers, and it will handle the rest. + +## How It Works + +1. **Input Files**: + - **Tweet Data (JSON)**: A file that contains your tweet history, typically exported from Twitter or captured via a web session. + - **Request Headers**: A file containing the session headers captured from your authenticated Twitter session (this can be done via browser developer tools). + +2. **Deletion Process**: + - The script scans the tweet data for replies (identified by the `in_reply_to_status_id_str` field being non-null). + - For each reply found, the script sends a delete request to Twitter's GraphQL API. + +## Usage + +### Prerequisites + +- **Python 3.x** installed on your system. +- **requests** library installed. You can install it using `pip`: + ```bash + pip install requests + + # de-x.py **This script can be used to delete the whole history of your tweets, retweets and replies.**