Last active
November 29, 2024 08:15
-
-
Save audiodude/cb8234b4957892a65af6608f0ac3c359 to your computer and use it in GitHub Desktop.
Delete all of your Mastodon posts using your token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import time | |
import requests | |
import tqdm | |
API_TOKEN = 'YOUR_API_TOKEN' | |
ACCOUNT_ID = 'YOUR_ACCOUNT_ID' | |
requested = False | |
while not requested or len(data) > 0: | |
requested = True | |
resp = requests.get(f'https://mastodon.online/api/v1/accounts/{ACCOUNT_ID}/statuses') | |
data = resp.json() | |
for status in data: | |
del_resp = requests.delete(f'https://mastodon.online/api/v1/statuses/{status['id']}', headers={'Authorization': f'Bearer {API_TOKEN}'}) | |
if del_resp.status_code == 429: | |
reset = del_resp.headers['X-RateLimit-Reset'] | |
reset_dt = datetime.strptime(reset, '%Y-%m-%dT%H:%M:%S.%fZ') | |
sleep_time = reset_dt - datetime.utcnow() | |
secs_rem = sleep_time.seconds | |
print(f'Rate limited until {reset}, which is {secs_rem} seconds from now') | |
for i in tqdm.tqdm(range(secs_rem)): | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment