From 9239a1fde5909f677378e4c9931c67441573a602 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:15:37 -0500 Subject: [PATCH 01/18] Update Makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 33df1d4..8013527 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ lint: go vet ./... staticcheck ./... +.PHONY: delete-reddit-history +delete-reddit-history: + go run .cmd/deleteRedditHistory/main.go + .PHONY: parse-slack-data parse-slack-data: go run ./cmd/slackMessageParser/main.go From 41187d1f7e1f1ad02ba16924acc9cba8327aa29e Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:58:01 -0500 Subject: [PATCH 02/18] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 057b692..d3a160e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ slack_records.csv .idea .vscode **/.DS_Store +.env* From c2896dcce0993120234d6f1ae6ae67ffd8d7ac90 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:58:08 -0500 Subject: [PATCH 03/18] Create main.go --- cmd/deleteRedditHistory/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 cmd/deleteRedditHistory/main.go diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go new file mode 100644 index 0000000..87ccfe0 --- /dev/null +++ b/cmd/deleteRedditHistory/main.go @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2025 Michael Plunkett (https://github.com/michplunkett) + * All rights reserved. + * Used to delete Reddit history of a given user. + */ + +package main + +func main() { + +} From 4a798301414e782cfd176167bc465567722af910 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:58:17 -0500 Subject: [PATCH 04/18] Add go-reddit --- go.mod | 2 ++ go.sum | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/go.mod b/go.mod index 37af3fe..ccd096e 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/michplunkett/golang-scripting go 1.22.4 require github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 + +require github.com/vartanbeno/go-reddit/v2 v2.0.1 // indirect diff --git a/go.sum b/go.sum index e47b2a7..bb38d27 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,19 @@ +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/vartanbeno/go-reddit/v2 v2.0.1 h1:P6ITpf5YHjdy7DHZIbUIDn/iNAoGcEoDQnMa+L4vutw= +github.com/vartanbeno/go-reddit/v2 v2.0.1/go.mod h1:758/S10hwZSLm43NPtwoNQdZFSg3sjB5745Mwjb0ANI= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 3b75aebd0b5495517cc9d25f82d3e7cea2d9c064 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:08:19 -0500 Subject: [PATCH 05/18] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3a160e..057b692 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,3 @@ slack_records.csv .idea .vscode **/.DS_Store -.env* From 30b2a55d273e21225e0415a184d94c86a5949845 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:26:30 -0500 Subject: [PATCH 06/18] Update main.go --- cmd/deleteRedditHistory/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index 87ccfe0..8ba4c8b 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -6,6 +6,13 @@ package main +type envVars struct { + appID string + appSecret string + userName string + userPassword string +} + func main() { } From 4ee564ceef99cd347eb0cba14495f45e22b5fc2a Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:39:15 -0500 Subject: [PATCH 07/18] Cleanin' up --- go.mod | 2 -- go.sum | 17 ----------------- 2 files changed, 19 deletions(-) diff --git a/go.mod b/go.mod index ccd096e..37af3fe 100644 --- a/go.mod +++ b/go.mod @@ -3,5 +3,3 @@ module github.com/michplunkett/golang-scripting go 1.22.4 require github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 - -require github.com/vartanbeno/go-reddit/v2 v2.0.1 // indirect diff --git a/go.sum b/go.sum index bb38d27..e47b2a7 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,2 @@ -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/vartanbeno/go-reddit/v2 v2.0.1 h1:P6ITpf5YHjdy7DHZIbUIDn/iNAoGcEoDQnMa+L4vutw= -github.com/vartanbeno/go-reddit/v2 v2.0.1/go.mod h1:758/S10hwZSLm43NPtwoNQdZFSg3sjB5745Mwjb0ANI= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From c1842aeadf5bc645e879298984169089f11585e4 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:39:18 -0500 Subject: [PATCH 08/18] Update main.go --- cmd/deleteRedditHistory/main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index 8ba4c8b..2259e5d 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -6,6 +6,12 @@ package main +import ( + "fmt" + "log" + "os" +) + type envVars struct { appID string appSecret string @@ -13,6 +19,25 @@ type envVars struct { userPassword string } +func arrayHasNoEmptyStrings(envVars []string) bool { + for _, value := range envVars { + if value == "" { + return false + } + } + + return true +} + func main() { + e := envVars{ + os.Getenv("REDDIT_APP_ID"), + os.Getenv("REDDIT_SECRET"), + os.Getenv("REDDIT_USER_ID"), + os.Getenv("REDDIT_USER_PASSWORD"), + } + if !arrayHasNoEmptyStrings([]string{e.appID, e.appSecret, e.userName, e.userPassword}) { + log.Fatal(fmt.Errorf("one of the last.fm environment variables is not present in your system")) + } } From 034c203dfc9c9eb7ebd89648d074941d56a5e238 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:45:09 -0500 Subject: [PATCH 09/18] Update main.go --- cmd/deleteRedditHistory/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index 2259e5d..9620439 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -10,6 +10,8 @@ import ( "fmt" "log" "os" + + "github.com/vartanbeno/go-reddit/v2/reddit" ) type envVars struct { @@ -40,4 +42,11 @@ func main() { if !arrayHasNoEmptyStrings([]string{e.appID, e.appSecret, e.userName, e.userPassword}) { log.Fatal(fmt.Errorf("one of the last.fm environment variables is not present in your system")) } + + credentials := reddit.Credentials{ID: e.appID, Secret: e.appSecret, Username: e.userName, Password: e.userPassword} + _, clientErr := reddit.NewClient(credentials) + + if clientErr != nil { + log.Fatal(clientErr) + } } From 27235058d6106f03432b268be3e64268bba34af6 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:45:16 -0500 Subject: [PATCH 10/18] add go-reddit --- go.mod | 9 +++++++++ go.sum | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/go.mod b/go.mod index 37af3fe..f27e216 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,12 @@ module github.com/michplunkett/golang-scripting go 1.22.4 require github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 + +require ( + github.com/golang/protobuf v1.2.0 // indirect + github.com/google/go-querystring v1.0.0 // indirect + github.com/vartanbeno/go-reddit/v2 v2.0.1 + golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e // indirect + golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect + google.golang.org/appengine v1.4.0 // indirect +) diff --git a/go.sum b/go.sum index e47b2a7..19e90bb 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,29 @@ +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ= github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/vartanbeno/go-reddit/v2 v2.0.1 h1:P6ITpf5YHjdy7DHZIbUIDn/iNAoGcEoDQnMa+L4vutw= +github.com/vartanbeno/go-reddit/v2 v2.0.1/go.mod h1:758/S10hwZSLm43NPtwoNQdZFSg3sjB5745Mwjb0ANI= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 4b692eaffd11354232996ab72951943dc4224f3f Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 5 Sep 2025 23:35:04 -0500 Subject: [PATCH 11/18] Fix Makefile path --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8013527..e9b821a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ lint: .PHONY: delete-reddit-history delete-reddit-history: - go run .cmd/deleteRedditHistory/main.go + go run ./cmd/deleteRedditHistory/main.go .PHONY: parse-slack-data parse-slack-data: From 26596e838575eab3967d274b26948c4bb714818f Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Sat, 6 Sep 2025 01:16:40 -0500 Subject: [PATCH 12/18] Add most of deletion logic --- cmd/deleteRedditHistory/main.go | 109 +++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index 9620439..78140b7 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -7,9 +7,11 @@ package main import ( + "context" "fmt" "log" "os" + "time" "github.com/vartanbeno/go-reddit/v2/reddit" ) @@ -21,6 +23,10 @@ type envVars struct { userPassword string } +const LIMIT = 100 + +var THRESHOLD = time.Now().AddDate(-2, 0, 0) + func arrayHasNoEmptyStrings(envVars []string) bool { for _, value := range envVars { if value == "" { @@ -32,6 +38,8 @@ func arrayHasNoEmptyStrings(envVars []string) bool { } func main() { + ctx := context.Background() + e := envVars{ os.Getenv("REDDIT_APP_ID"), os.Getenv("REDDIT_SECRET"), @@ -44,9 +52,108 @@ func main() { } credentials := reddit.Credentials{ID: e.appID, Secret: e.appSecret, Username: e.userName, Password: e.userPassword} - _, clientErr := reddit.NewClient(credentials) + cli, clientErr := reddit.NewClient(credentials) if clientErr != nil { log.Fatal(clientErr) } + + // Get overview of user + commentService := *cli.Comment + postService := *cli.Post + userService := *cli.User + + // Get all posts + fmt.Println("------- Pulling user posts. -------") + + lastPostID := "" + postIds := make([]string, 0) + postOptions := &reddit.ListUserOverviewOptions{ + ListOptions: reddit.ListOptions{ + Limit: LIMIT, + }, + Sort: "new", + Time: "all", + } + for { + if lastPostID != "" { + postOptions.ListOptions.After = lastPostID + } + + fmt.Println("Pulling more posts.") + posts, _, err := userService.Posts(ctx, postOptions) + if err != nil { + log.Fatal(err) + } + + if len(posts) == 0 { + break + } + + for _, post := range posts { + if post.Created.Time.Before(THRESHOLD) || + post.Created.Time.Equal(THRESHOLD) { + fmt.Println(post.Created) + postIds = append(postIds, post.FullID) + } + } + + lastPostID = posts[len(posts)-1].FullID + } + + // Delete all posts + fmt.Println("------- Deleting user posts. -------") + for _, pID := range postIds { + fmt.Println(pID) + //_, err := postService.Delete(ctx, pID) + //if err != nil { + // log.Fatal(err) + //} + } + + // Get all comments + fmt.Println("------- Pulling user comments. -------") + lastCommentID := "" + commentIds := make([]string, 0) + commentOptions := &reddit.ListUserOverviewOptions{ + ListOptions: reddit.ListOptions{ + Limit: LIMIT, + }, + Sort: "new", + Time: "all", + } + for { + if lastCommentID != "" { + commentOptions.ListOptions.After = lastCommentID + } + + fmt.Println("Pulling more comments.") + comments, _, err := userService.Comments(ctx, commentOptions) + if err != nil { + log.Fatal(err) + } + + if len(comments) == 0 { + break + } + + for _, c := range comments { + if c.Created.Time.Before(THRESHOLD) || + c.Created.Time.Equal(THRESHOLD) { + commentIds = append(commentIds, c.FullID) + } + } + + lastCommentID = comments[len(comments)-1].FullID + } + + // Delete all comments + fmt.Println("------- Deleting user comments. -------") + for _, cID := range commentIds { + fmt.Println(cID) + //_, err := commentService.Delete(ctx, cID) + //if err != nil { + // log.Fatal(err) + //} + } } From 671f0ecfc34f31b6565ea20b3eb104ede437daab Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Sat, 6 Sep 2025 01:25:17 -0500 Subject: [PATCH 13/18] Modified comments --- cmd/deleteRedditHistory/main.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index 78140b7..ce32ea9 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -1,7 +1,7 @@ /* * Copyright (c) 2025 Michael Plunkett (https://github.com/michplunkett) * All rights reserved. - * Used to delete Reddit history of a given user. + * Used to delete Reddit user posts and comments older than a given threshold date. */ package main @@ -53,18 +53,17 @@ func main() { credentials := reddit.Credentials{ID: e.appID, Secret: e.appSecret, Username: e.userName, Password: e.userPassword} cli, clientErr := reddit.NewClient(credentials) - if clientErr != nil { log.Fatal(clientErr) } // Get overview of user - commentService := *cli.Comment - postService := *cli.Post + _ = *cli.Comment + _ = *cli.Post userService := *cli.User // Get all posts - fmt.Println("------- Pulling user posts. -------") + fmt.Println("------- Pulling user posts") lastPostID := "" postIds := make([]string, 0) @@ -80,7 +79,6 @@ func main() { postOptions.ListOptions.After = lastPostID } - fmt.Println("Pulling more posts.") posts, _, err := userService.Posts(ctx, postOptions) if err != nil { log.Fatal(err) @@ -93,7 +91,6 @@ func main() { for _, post := range posts { if post.Created.Time.Before(THRESHOLD) || post.Created.Time.Equal(THRESHOLD) { - fmt.Println(post.Created) postIds = append(postIds, post.FullID) } } @@ -102,7 +99,7 @@ func main() { } // Delete all posts - fmt.Println("------- Deleting user posts. -------") + fmt.Println("------- Deleting user posts:", len(postIds)) for _, pID := range postIds { fmt.Println(pID) //_, err := postService.Delete(ctx, pID) @@ -112,7 +109,8 @@ func main() { } // Get all comments - fmt.Println("------- Pulling user comments. -------") + fmt.Println("------- Pulling user comments") + lastCommentID := "" commentIds := make([]string, 0) commentOptions := &reddit.ListUserOverviewOptions{ @@ -127,7 +125,6 @@ func main() { commentOptions.ListOptions.After = lastCommentID } - fmt.Println("Pulling more comments.") comments, _, err := userService.Comments(ctx, commentOptions) if err != nil { log.Fatal(err) @@ -148,7 +145,8 @@ func main() { } // Delete all comments - fmt.Println("------- Deleting user comments. -------") + fmt.Println("------- Deleting user comments:", len(commentIds)) + for _, cID := range commentIds { fmt.Println(cID) //_, err := commentService.Delete(ctx, cID) From eb6c7028f4d6236cd870326751dca85e39911247 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Sat, 6 Sep 2025 01:30:12 -0500 Subject: [PATCH 14/18] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d29a85..6344ebd 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,17 @@ Various scripts written in Golang. ## Scripts +### Reddit Comment and Post Deleter +This is used to delete all comments for a given user that are older than 2-years-old. To properly configure, please +create the following environment variables: `REDDIT_USER_ID`, `REDDIT_USER_PASSWORD`, `REDDIT_APP_ID`, `REDDIT_SECRET`. + +For information regarding the acquisition of values for the above environment variables, please +check here: [Link](https://github.com/reddit-archive/reddit/wiki/OAuth2-Quick-Start-Example#first-steps). + ### Slack Message Parser -This tool is used to parse the `json`-formatted data that comes from [exporting Slack workspace data](https://slack.com/help/articles/201658943-Export-your-workspace-data) into a `csv` file named: `slack_records.csv`. +This script is used to parse the `json`-formatted data that comes from +[exporting Slack workspace data](https://slack.com/help/articles/201658943-Export-your-workspace-data) into a `csv` +file named: `slack_records.csv`. | TimeStamp | UserID | UserName | RealName | MessageType | Text | Attachments | Files | |:---------:|:------:|:--------:|:--------:|:-----------:|:------:|:-----------:|:--------:| From 49fde4d4a3e997c67248086999ae0a5e669d7ed6 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:41:09 -0500 Subject: [PATCH 15/18] Update main.go --- cmd/deleteRedditHistory/main.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/deleteRedditHistory/main.go b/cmd/deleteRedditHistory/main.go index ce32ea9..fb1dfbb 100644 --- a/cmd/deleteRedditHistory/main.go +++ b/cmd/deleteRedditHistory/main.go @@ -1,7 +1,7 @@ /* * Copyright (c) 2025 Michael Plunkett (https://github.com/michplunkett) * All rights reserved. - * Used to delete Reddit user posts and comments older than a given threshold date. + * Used to delete Reddit user posts and comments older than 2-years-old. */ package main @@ -58,8 +58,8 @@ func main() { } // Get overview of user - _ = *cli.Comment - _ = *cli.Post + commentService := *cli.Comment + postService := *cli.Post userService := *cli.User // Get all posts @@ -101,11 +101,10 @@ func main() { // Delete all posts fmt.Println("------- Deleting user posts:", len(postIds)) for _, pID := range postIds { - fmt.Println(pID) - //_, err := postService.Delete(ctx, pID) - //if err != nil { - // log.Fatal(err) - //} + _, err := postService.Delete(ctx, pID) + if err != nil { + log.Fatal(err) + } } // Get all comments @@ -148,10 +147,9 @@ func main() { fmt.Println("------- Deleting user comments:", len(commentIds)) for _, cID := range commentIds { - fmt.Println(cID) - //_, err := commentService.Delete(ctx, cID) - //if err != nil { - // log.Fatal(err) - //} + _, err := commentService.Delete(ctx, cID) + if err != nil { + log.Fatal(err) + } } } From 300e1946814f5b65ccd113bb09c666bf7ad12016 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:49:37 -0500 Subject: [PATCH 16/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6344ebd..dc9457b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Various scripts written in Golang. ## Scripts ### Reddit Comment and Post Deleter -This is used to delete all comments for a given user that are older than 2-years-old. To properly configure, please +This script deletes all comments for a given user that are older than 2 years old. To properly configure, please create the following environment variables: `REDDIT_USER_ID`, `REDDIT_USER_PASSWORD`, `REDDIT_APP_ID`, `REDDIT_SECRET`. For information regarding the acquisition of values for the above environment variables, please From 43a0b389181733cb9bd1974f0e4cac2720b43b65 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:50:34 -0500 Subject: [PATCH 17/18] Update audit.yml --- .github/workflows/audit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index f2fffad..8b345d5 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.22 + go-version: 1.23 - name: Verify dependencies run: go mod verify From 7fd3aa7c6594119cd8801607451c75e14cf20831 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:53:07 -0500 Subject: [PATCH 18/18] Update audit.yml --- .github/workflows/audit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 8b345d5..d82b9c2 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -9,7 +9,7 @@ on: jobs: audit: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2