Lyfhael/DeleteTweets

Python script to extract headers quickly

Opened this issue · 0 comments

av1d commented

I've made a fast way to obtain the credentials.

To use this, you want to load Twitter/X, open the DevTools by pressing CTRL + SHIFT + I, filter by Fetch/XHR, refresh the page.
Right-click something, click "Copy", then "copy all as cURL".
Run the python script python extract.py or whatever, then paste what you copied into it. Press enter twice.

import re

def extract_headers(curl_command):
    # headers you want to extract
    headers_to_extract = [
        'authorization',
        'x-client-uuid',
        'x-client-transaction-id'
    ]
    
    # regex pattern to match the headers
    pattern = re.compile(r"-H '([^:]+): ([^']+)'")
    
    extracted_headers = {}

    # find all headers
    for match in pattern.finditer(curl_command):
        header_name = match.group(1).strip().lower()
        header_value = match.group(2).strip()

        if header_name in headers_to_extract:
            extracted_headers[header_name] = header_value

    return extracted_headers

def main():

    print("Paste your curl command below (end with an empty line):")
    curl_command = []
    
    while True:
        line = input()
        if line.strip() == "":
            break
        curl_command.append(line)
    
    curl_command_str = "\n".join(curl_command)

    # extract headers
    headers = extract_headers(curl_command_str)

    # print result
    for key, value in headers.items():
        print(f"-H '{key}: {value}'")

if __name__ == "__main__":
    main()