commit ca33882a97cd670c62a55f1cbb33ac8888a92b5d
parent 5632b90e5ebdc029f010fa4cc35c8e5057836594
Author: alex wennerberg <alex@alexwennerberg.com>
Date: Sun, 17 Oct 2021 00:41:12 -0700
Cleanup delete script
Diffstat:
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/mastodon-delete.go b/mastodon-delete.go
@@ -2,9 +2,20 @@ package main
// Make your mastodon posts ephemeral by deleting old posts
// Dies on rate limit. Designed to periodically run on cron, Not a one-time clear.
-// Write a wrapper script if you want that.
+// Write a wrapper script if you want that, but keep in mind the rate
+// limit for deleting statuses is very low.
// Not thoroughly tested, caveat emptor
+// To create an application: go to Preferences > Development > New Application
+// Make sure the app has read:statuses and write:statuses. Then copy the access
+// Token "Your access token" into the config file, like this:
+
+// server=https://yourserver.domain
+// access_token=longkeystring
+
+// go build mastodon-delete.go
+// ./mastodon-delete -c [config filepath] -d [delete statuses older than this many days]
+
import (
"bufio"
"encoding/json"
@@ -80,16 +91,13 @@ func main() {
}{}
err = json.Unmarshal(resp, account)
if err != nil {
- log.Println(string(resp))
log.Fatal(err)
}
- me_id := account.Id
-
var max_id string
cutoff := time.Now().UTC().AddDate(0, 0, *days*-1).Format(time.RFC3339)
for {
- url := "/api/v1/accounts/" + me_id + "/statuses"
+ url := "/api/v1/accounts/" + account.Id + "/statuses"
if max_id != "" {
url += "?max_id=" + max_id
}
@@ -102,10 +110,9 @@ func main() {
Content string
CreatedAt string `json:"created_at"`
}{}
- // Assumes result is already sorted
+ // Assumes result is already date sorted
err = json.Unmarshal(resp, &statuses)
if err != nil {
- log.Println(string(resp))
log.Fatal(err)
}
if len(statuses) == 0 {