misc

Misc scripts and tools
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 8dbabcb60c40869bee77826f174615b8e087229d
parent ca33882a97cd670c62a55f1cbb33ac8888a92b5d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 17 Oct 2021 19:54:48 -0700

Add dryrun flag

Diffstat:
Mmastodon-delete.go | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mastodon-delete.go b/mastodon-delete.go @@ -59,8 +59,12 @@ func (client *MastodonClient) do(method string, endpoint string) ([]byte, error) func main() { var configPath = flag.String("c", "config.txt", "config file path") var days = flag.Int("d", 90, "will delete statuses older than this many days") + var dryrun = flag.Bool("dryrun", false, "don't actually delete anything, just list what will be deleted") flag.Parse() fmt.Println("Deleting all statuses older than", *days, "days") + if *dryrun { + fmt.Println("DRY RUN -- NOT ACTUALLY DELETING ANYTHING") + } file, err := os.Open(*configPath) if err != nil { log.Fatal(err) @@ -122,9 +126,11 @@ func main() { for _, status := range statuses { if status.CreatedAt < cutoff { // RFC 3339 date strings are sortable fmt.Printf("Deleting status %s: '%s'\n", status.Id, status.Content) - _, err := client.do("DELETE", "/api/v1/statuses/"+status.Id) - if err != nil { - log.Fatal(err) + if !*dryrun { + _, err := client.do("DELETE", "/api/v1/statuses/"+status.Id) + if err != nil { + log.Fatal(err) + } } } }