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