arnaucube
arnaucube/argosPublic Self-hosted repository
argos/optionFollowRandom.go
optionFollowRandom.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 waitTime(minutes int) {
15	//wait to avoid the twitter api limitation
16	timeToSleep := time.Duration(minutes) * time.Minute
17	fmt.Println("waiting " + strconv.Itoa(minutes) + " min to avoid twitter api limitation")
18	fmt.Println(time.Now().Local())
19	time.Sleep(timeToSleep)
20}
21func getUserToFollowFromUser(client *twitter.Client, fromUser string) string {
22	friends, httpResp, err := client.Friends.List(&twitter.FriendListParams{
23		ScreenName: fromUser,
24		Count:      1,
25	})
26	if err != nil {
27		fmt.Println(err)
28	}
29	if httpResp.Status != "200 OK" {
30		c.Red(httpResp.Status)
31	}
32	//fmt.Println(friends.Users)
33	//c.Green("@" + friends.Users[0].ScreenName)
34	return friends.Users[0].ScreenName
35}
36
37func followUser(client *twitter.Client, screenName string) {
38	user, _, _ := client.Friendships.Create(&twitter.FriendshipCreateParams{
39		ScreenName: screenName,
40	})
41	fmt.Print("followed: ")
42	c.Green("@" + user.ScreenName + " - " + user.Description)
43}
44
45func followRandom(client *twitter.Client, nFollow int, screenName string) {
46	fmt.Println("Starting to follow " + strconv.Itoa(nFollow) + " users")
47	//screenName := firstScreenName
48	for i := 0; i < nFollow; i++ {
49		userToFollow := getUserToFollowFromUser(client, screenName)
50		followUser(client, userToFollow)
51		screenName = userToFollow
52		waitTime(1)
53	}
54
55}
56
57func optionFollowRandom(client *twitter.Client) {
58	c.Red("how many accounts to follow?")
59	newcommand := bufio.NewReader(os.Stdin)
60	answer, _ := newcommand.ReadString('\n')
61	answer = strings.TrimSpace(answer)
62	fmt.Print("Number of users to follow: ")
63	c.Purple(answer)
64	nFollow, err := strconv.Atoi(answer)
65	if err != nil {
66		fmt.Println("incorrect entry, need a positive number")
67	}
68
69	fmt.Print("entry @username of a user, to get a 1st user to follow, that will be a user that the 1st user is following, and the 2nd user will be a user that the 3rd user is following): @")
70	newcommand = bufio.NewReader(os.Stdin)
71	firstScreenName, _ := newcommand.ReadString('\n')
72	firstScreenName = strings.TrimSpace(firstScreenName)
73	fmt.Print("first user to follow: @")
74	c.Purple(firstScreenName)
75
76	c.Red("Are you sure? [y/n]")
77	newcommand = bufio.NewReader(os.Stdin)
78	answer, _ = newcommand.ReadString('\n')
79	answer = strings.TrimSpace(answer)
80	switch answer {
81	case "y":
82		fmt.Println("ok, you are sure")
83		followRandom(client, nFollow, firstScreenName)
84		break
85	default:
86		fmt.Println("Operation cancelled")
87		break
88	}
89}