Skip to content

Instantly share code, notes, and snippets.

@safiire
Last active October 12, 2022 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safiire/93b94fd1f6c044c0ae624be54f917820 to your computer and use it in GitHub Desktop.
Save safiire/93b94fd1f6c044c0ae624be54f917820 to your computer and use it in GitHub Desktop.
Delete all My Reddit Comments
#!/bin/bash
LIMIT='100'
SLEEP='1'
TOKEN='xxxxxxx-xxxxxxxxxxxxxxxxxx-xxxx-xxxxxx'
USERNAME='username'
# Delete a comment by id
function delete_comment() {
local comment_id="$1"
local response
response=$(
curl -s 'https://oauth.reddit.com/api/del?raw_json=1' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0' \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-raw "id=t1_${comment_id}"
)
}
# Delete LIMIT comments after the given id
function delete_comment_ids_after() {
local after="$1"
local response
echo "Fetching ${LIMIT} comment ids" >&2
response=$(
curl -s "https://oauth.reddit.com/user/${USERNAME}/comments.json?raw_json=1&limit=${LIMIT}&after=${after}" \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0' \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/x-www-form-urlencoded' | jq
)
local comment_ids=$(echo $response | jq -r '.data.children[].data.id')
local last_id=$(echo $response | jq -r '.data.children[-1].data.id')
for comment_id in $comment_ids; do
echo "Deleting $comment_id" >&2
delete_comment "$comment_id"
sleep "${SLEEP}"
done
echo "$last_id"
}
# Delete all comments in your account
function delete_all_comments() {
local after=''
while true; do
after=$(delete_comment_ids_after "$after")
done
}
delete_all_comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment