@@ -5,9 +5,12 @@ import (
55 "fmt"
66 "log"
77 "os"
8+ "strings"
89 "sync"
910 "time"
1011
12+ "github.com/palantir/stacktrace"
13+
1114 "github.com/NdoleStudio/httpsms/pkg/di"
1215 "github.com/NdoleStudio/httpsms/pkg/entities"
1316 "github.com/google/uuid"
@@ -27,11 +30,36 @@ func main() {
2730 logger := container .Logger ()
2831
2932 logger .Info ("Starting experiments" )
33+ }
34+
35+ func chunkBy [T any ](items []T , chunkSize int ) (chunks [][]T ) {
36+ for chunkSize < len (items ) {
37+ items , chunks = items [chunkSize :], append (chunks , items [0 :chunkSize :chunkSize ])
38+ }
39+ return append (chunks , items )
40+ }
3041
42+ func deleteContacts (container * di.Container ) {
3143 sendgrid := container .MarketingService ()
32- err = sendgrid .ClearList (context .Background ())
44+ logger := container .Logger ()
45+
46+ b , err := os .ReadFile ("28462979_cf6f5478-3e15-4666-95d7-59149df6f0fd.csv" ) // just pass the file name
3347 if err != nil {
34- logger .Fatal (err )
48+ logger .Fatal (stacktrace .Propagate (err , "cannot read file" ))
49+ }
50+
51+ lines := strings .Split (string (b ), "\n " )[1 :]
52+ var contacts []string
53+ for _ , line := range lines {
54+ contacts = append (contacts , strings .ReplaceAll (strings .Split (line , "," )[17 ], "\" " , "" ))
55+ }
56+
57+ chunks := chunkBy (contacts , 100 )
58+ for _ , chunk := range chunks {
59+ err = sendgrid .DeleteContacts (context .Background (), chunk )
60+ if err != nil {
61+ logger .Fatal (err )
62+ }
3563 }
3664}
3765
0 commit comments