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
| package main
import (
"bufio"
"net/url"
"os"
"strconv"
"strings"
"time"
"log"
"github.com/ChimeraCoder/anaconda"
)
var (
consumerKey = getenv("TWITTER_CONSUMER_KEY")
consumerSecret = getenv("TWITTER_CONSUMER_SECRET")
accessToken = getenv("TWITTER_ACCESS_TOKEN")
accessTokenSecret = getenv("TWITTER_ACCESS_TOKEN_SECRET")
)
func getenv(name string) string {
v := os.Getenv(name)
if v == "" {
panic("missing required environment variable " + name)
}
return v
}
func getTimeline(api *anaconda.TwitterApi) ([]anaconda.Tweet, error) {
args := url.Values{}
args.Add("count", "200") // Twitter only returns most recent 20 tweets by default, so override
args.Add("include_rts", "true") // When using count argument, RTs are excluded, so include them as recommended
timeline, err := api.GetUserTimeline(args)
if err != nil {
return make([]anaconda.Tweet, 0), err
}
return timeline, nil
}
func deleteFromTimeline(api *anaconda.TwitterApi) int {
count := 0
already := 0
suspended := 0
blocked := 0
failed := 0
doomed, err := os.Open("doomed.list")
if err != nil {
log.Fatal("could not get deletion list", err)
}
defer doomed.Close()
scanner := bufio.NewScanner(doomed)
for scanner.Scan() {
time.Sleep(time.Second / 2)
id, err := strconv.ParseInt(scanner.Text(), 10, 64)
if err != nil {
failed++
log.Print("failed to parse doomed: ", err)
continue
}
_, err = api.DeleteTweet(id, true)
if err != nil {
if strings.Contains(err.Error(), "No status found with that ID.") {
already++
if already%100 == 0 {
log.Print("ALREADY DELETED COUNT ", already)
}
} else if strings.Contains(err.Error(), "User has been suspended.") {
suspended++
log.Print("SUSPENDED ID ", id)
} else if strings.Contains(err.Error(), "Sorry, you are not authorized to see this status.") {
blocked++
log.Print("SUSPENDED ID ", id)
} else {
failed++
log.Print("failed to delete: ", err)
}
continue
}
log.Print("DELETED ID ", id)
count++
}
log.Print("no more tweets to delete")
log.Printf("Totals: %d deleted, %d already deleted, %d suspended, %d blocked, %d failed",
count, already, suspended, blocked, failed)
return count
}
func main() {
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
api.SetLogger(anaconda.BasicLogger)
count := deleteFromTimeline(api)
if count == 0 {
os.Exit(1)
}
}
|