argos/optionUnfollowAll.go
optionUnfollowAll.goRaw
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "os"
7 "strconv"
8 "strings"
9
10 "github.com/dghubble/go-twitter/twitter"
11)
12
13func printUserFollowsData(user *twitter.User) {
14 fmt.Print("followers: ")
15 c.Cyan(strconv.Itoa(user.FollowersCount))
16 fmt.Print("following: ")
17 c.Cyan(strconv.Itoa(user.FriendsCount))
18}
19func unfollowUser(client *twitter.Client, screenName string) {
20 user, httpResp, _ := client.Friendships.Destroy(&twitter.FriendshipDestroyParams{
21 ScreenName: screenName,
22 })
23 if httpResp.Status != "200 OK" {
24 c.Red(httpResp.Status)
25 }
26 c.Green(user.ScreenName)
27}
28func getFollowingUsers(client *twitter.Client, user *twitter.User) {
29 following, httpResp, err := client.Friends.List(&twitter.FriendListParams{
30 ScreenName: user.ScreenName,
31 Count: 200,
32 })
33 if err != nil {
34 fmt.Println(err)
35 }
36 if httpResp.Status != "200 OK" {
37 c.Red(httpResp.Status)
38 }
39 for _, k := range following.Users {
40 unfollowUser(client, k.ScreenName)
41 //wait to avoid the twitter api limitation
42 /*fmt.Println("waiting 1 min to avoid twitter api limitation")
43 fmt.Println(time.Now().Local())
44 time.Sleep(1 * time.Minute)*/
45 }
46}
47func optionUnfollowAll(client *twitter.Client) {
48 fmt.Println("Getting user data...")
49 user := getUserData(client)
50 printUserFollowsData(user)
51 fmt.Println("")
52 c.Red("Are you sure you want to unfollow all? [y/n]")
53 newcommand := bufio.NewReader(os.Stdin)
54 answer, _ := newcommand.ReadString('\n')
55 answer = strings.TrimSpace(answer)
56 switch answer {
57 case "y":
58 fmt.Println("ok, you are sure")
59 getFollowingUsers(client, user)
60 break
61 default:
62 fmt.Println("Operation cancelled")
63 break
64 }
65}