I am running a gotosocial instance for my personal experiments. One of the bots I am running there is firstname.lastname@example.org which toots the current time every hour to give a feeling for time in my timeline.
I wanted to prune the old toots of this bot, because they are useless when older than a few days. Mastodon has a feature to prune older statuses, but gotosocial is missing this currently. There is a ready to use Python script to use for Mastodon named ephemetoot. But this fails for gotosocial because the version reported is not bigger than 1.0 (which would be the Mastodon version needed). So I needed to write code against the api myself (again).
First getting the account id of the current logged in user:
Then get the next 30 (gotosocial default) statuses:
The max_id has to be set to the previously last status to get the next 30 statuses. This is the way the Mastodon API is doing pagination.
And finally deleting a status:
The status code should be 200. For ratelimiting the code is 429.
Deleting a lot of statuses obviously results in a rate limit. Which is good! So maybe more than one run (after waiting for 15 minutes) is needed to prune all old toots. The script breaks (on purpose) when a rate limit happens.
The full code of the script is in the stuendlich-bot github repo.
The code is running in a Github Action once a day.