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