-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (55 loc) · 1.33 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"os"
"reflect"
"runtime"
"strings"
"github.com/crueber/twitter-pruner/pruner"
"github.com/dghubble/go-twitter/twitter"
"github.com/mkideal/cli"
)
// Pruner is for each of the pruning functions
type Pruner func(*pruner.Client, *twitter.User) error
func main() {
cli.Run(new(pruner.Env), func(ctx *cli.Context) error {
twitterEnv := ctx.Argv().(*pruner.Env)
client, err := twitterEnv.GenerateClient()
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
user, err := Verify(client)
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
var fns []interface{}
if twitterEnv.InclTweets {
fns = append(fns, PruneTimeline)
}
if twitterEnv.InclLikes {
fns = append(fns, PruneLikes)
}
for _, fn := range fns {
if twitterEnv.MaxAPICalls <= 0 {
fmt.Println("Max number of twitter interactions reached for this run.")
break
}
fmt.Printf("Started %v\n", strings.Replace(runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name(), "main.", "", 1))
f := fn.(func(*pruner.Client, *twitter.User) error)
err := Pruner(f)(client, user)
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
}
fmt.Println("Done")
return nil
})
}
func prettyPrint(i interface{}) string {
s, _ := json.MarshalIndent(i, "", " ")
return string(s)
}