argos/unfollowAll.go
unfollowAll.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 _, httpResp, _ := client.Friendships.Destroy(&twitter.FriendshipDestroyParams{
21 ScreenName: screenName,
22 })
23 if httpResp.Status != "200 OK" {
24 c.Red(httpResp.Status)
25 }
26}
27func getFollowingUsers(client *twitter.Client, user *twitter.User) {
28 following, httpResp, err := client.Friends.List(&twitter.FriendListParams{
29 ScreenName: user.ScreenName,
30 Count: 200,
31 })
32 if err != nil {
33 fmt.Println(err)
34 }
35 if httpResp.Status != "200 OK" {
36 c.Red(httpResp.Status)
37 }
38 fmt.Println(following)
39 for _, k := range following.Users {
40 unfollowUser(client, k.ScreenName)
41 }
42}
43func optionUnfollowAll(client *twitter.Client) {
44 fmt.Println("Getting user data...")
45 user := getUserData(client)
46 printUserFollowsData(user)
47 fmt.Println("")
48 c.Red("Are you sure you want to unfollow all? [y/n]")
49 newcommand := bufio.NewReader(os.Stdin)
50 answer, _ := newcommand.ReadString('\n')
51 answer = strings.TrimSpace(answer)
52 switch answer {
53 case "y":
54 fmt.Println("ok, you are sure")
55 getFollowingUsers(client, user)
56 break
57 default:
58 fmt.Println("Operation cancelled")
59 break
60 }
61}