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