You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.5 KiB

  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "github.com/dghubble/go-twitter/twitter"
  10. )
  11. func waitTime(minutes int) {
  12. //wait to avoid the twitter api limitation
  13. timeToSleep := time.Duration(minutes) * time.Minute
  14. fmt.Println("waiting " + strconv.Itoa(minutes) + " min to avoid twitter api limitation")
  15. fmt.Println(time.Now().Local())
  16. time.Sleep(timeToSleep)
  17. }
  18. func 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. func followUser(client *twitter.Client, screenName string) {
  34. user, _, _ := client.Friendships.Create(&twitter.FriendshipCreateParams{
  35. ScreenName: screenName,
  36. })
  37. fmt.Print("followed: ")
  38. c.Green("@" + user.ScreenName + " - " + user.Description)
  39. }
  40. func 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. waitTime(1)
  48. }
  49. }
  50. func 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. 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): @")
  62. newcommand = bufio.NewReader(os.Stdin)
  63. firstScreenName, _ := newcommand.ReadString('\n')
  64. firstScreenName = strings.TrimSpace(firstScreenName)
  65. fmt.Print("first user to follow: @")
  66. c.Purple(firstScreenName)
  67. c.Red("Are you sure? [y/n]")
  68. newcommand = bufio.NewReader(os.Stdin)
  69. answer, _ = newcommand.ReadString('\n')
  70. answer = strings.TrimSpace(answer)
  71. switch answer {
  72. case "y":
  73. fmt.Println("ok, you are sure")
  74. followRandom(client, nFollow, firstScreenName)
  75. break
  76. default:
  77. fmt.Println("Operation cancelled")
  78. break
  79. }
  80. }