-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter-wipe.go
126 lines (108 loc) · 3.16 KB
/
twitter-wipe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"reflect"
"time"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
var config struct {
Username *string `json:"Username"`
ConsumerKey *string `json:"ConsumerKey"`
ConsumerSecret *string `json:"ConsumerSecret"`
AccessToken *string `json:"AccessToken"`
AccessSecret *string `json:"AccessSecret"`
DeleteTweets *bool `json:"DeleteTweets"`
DeleteRetweets *bool `json:"DeleteRetweets"`
DeleteLikes *bool `json:"DeleteLikes"`
}
func main() {
// Open our config file
file, err := os.Open("config.json")
if err != nil {
log.Fatal("Cannot open config.json: ", err)
}
// Decode our config file into our struct
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
log.Fatal("Cannot load JSON config into config.struct: ", err)
}
configTest := reflect.ValueOf(config)
configType := configTest.Type()
for i := 0; i < configTest.NumField(); i++ {
if configTest.Field(i).IsNil() {
log.Fatal("Required JSON value was not defined: ", configType.Field(i).Name)
}
}
fmt.Println(" Starting..")
oauthConfig := oauth1.NewConfig(*config.ConsumerKey, *config.ConsumerSecret)
token := oauth1.NewToken(*config.AccessToken, *config.AccessSecret)
// http.Client will automatically authorize Requests
httpClient := oauthConfig.Client(oauth1.NoContext, token)
// twitter client
client := twitter.NewClient(httpClient)
// Delete tweets and retweets
if *config.DeleteTweets || *config.DeleteRetweets {
fmt.Println(" Deleting tweets and retweets..")
for true {
tweets, _, err := client.Timelines.UserTimeline(&twitter.UserTimelineParams{
ScreenName: *config.Username,
Count: 20,
TrimUser: twitter.Bool(true),
IncludeRetweets: twitter.Bool(true),
})
if err != nil {
log.Fatal("Failed to get tweets: ", err)
}
if len(tweets) == 0 {
fmt.Println(" No (re)tweets remain.")
break
}
for _, tweet := range tweets {
if tweet.Retweeted {
if *config.DeleteRetweets {
fmt.Printf(" Deleting: retweeted id: %v\n", tweet.ID)
params := &twitter.StatusUnretweetParams{TrimUser: twitter.Bool(true)}
client.Statuses.Unretweet(tweet.ID, params)
}
} else {
if *config.DeleteTweets {
fmt.Printf(" Deleting: tweeted id: %v\n", tweet.ID)
params := &twitter.StatusDestroyParams{TrimUser: twitter.Bool(true)}
client.Statuses.Destroy(tweet.ID, params)
}
}
time.Sleep(10 * time.Second)
}
}
}
// Delete likes
if *config.DeleteLikes {
fmt.Println(" Deleting likes..")
for true {
tweets, _, err := client.Favorites.List(&twitter.FavoriteListParams{
ScreenName: *config.Username,
Count: 20,
})
if err != nil {
log.Fatal("Failed to get tweets: ", err)
}
if len(tweets) == 0 {
fmt.Println(" No likes remain.")
break
}
for _, tweet := range tweets {
fmt.Printf(" Deleting: liked id: %v\n", tweet.ID)
params := &twitter.FavoriteDestroyParams{ID: tweet.ID}
client.Favorites.Destroy(params)
time.Sleep(10 * time.Second)
}
}
}
// Done
fmt.Println(" Done.")
}