arnaucube
arnaucube/argosPublic Self-hosted repository
argos/optionUnfollowAll.go
optionUnfollowAll.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	for _, k := range following.Users {
41		unfollowUser(client, k.ScreenName)
42		//wait to avoid the twitter api limitation
43		fmt.Println("waiting 1 min to avoid twitter api limitation")
44		fmt.Println(time.Now().Local())
45		time.Sleep(1 * time.Minute)
46	}
47}
48func optionUnfollowAll(client *twitter.Client) {
49	fmt.Println("Getting user data...")
50	user := getUserData(client)
51	printUserFollowsData(user)
52	fmt.Println("")
53	c.Red("Are you sure you want to unfollow all? [y/n]")
54	newcommand := bufio.NewReader(os.Stdin)
55	answer, _ := newcommand.ReadString('\n')
56	answer = strings.TrimSpace(answer)
57	switch answer {
58	case "y":
59		fmt.Println("ok, you are sure")
60		getFollowingUsers(client, user)
61		break
62	default:
63		fmt.Println("Operation cancelled")
64		break
65	}
66}