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.

87 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. c.Purple("maybe twitter has blocked the account, CTRL+C, wait 15 minutes and try again")
  29. }
  30. return friends.Users[0].ScreenName
  31. }
  32. func followUser(client *twitter.Client, screenName string) {
  33. user, _, _ := client.Friendships.Create(&twitter.FriendshipCreateParams{
  34. ScreenName: screenName,
  35. })
  36. fmt.Print("followed: ")
  37. c.Green("@" + user.ScreenName + " - " + user.Description)
  38. }
  39. func followRandom(client *twitter.Client, nFollow int, screenName string) {
  40. fmt.Println("Starting to follow " + strconv.Itoa(nFollow) + " users")
  41. for i := 0; i < nFollow; i++ {
  42. userToFollow := getUserToFollowFromUser(client, screenName)
  43. followUser(client, userToFollow)
  44. screenName = userToFollow
  45. waitTime(1)
  46. }
  47. }
  48. func optionFollowRandom(client *twitter.Client) {
  49. c.Red("how many accounts to follow?")
  50. newcommand := bufio.NewReader(os.Stdin)
  51. answer, _ := newcommand.ReadString('\n')
  52. answer = strings.TrimSpace(answer)
  53. fmt.Print("Number of users to follow: ")
  54. c.Purple(answer)
  55. nFollow, err := strconv.Atoi(answer)
  56. if err != nil {
  57. fmt.Println("incorrect entry, need a positive number")
  58. }
  59. 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): @")
  60. newcommand = bufio.NewReader(os.Stdin)
  61. firstScreenName, _ := newcommand.ReadString('\n')
  62. firstScreenName = strings.TrimSpace(firstScreenName)
  63. fmt.Print("first user to follow: @")
  64. c.Purple(firstScreenName)
  65. c.Red("Are you sure? [y/n]")
  66. newcommand = bufio.NewReader(os.Stdin)
  67. answer, _ = newcommand.ReadString('\n')
  68. answer = strings.TrimSpace(answer)
  69. switch answer {
  70. case "y":
  71. fmt.Println("ok, you are sure")
  72. followRandom(client, nFollow, firstScreenName)
  73. break
  74. default:
  75. fmt.Println("Operation cancelled")
  76. break
  77. }
  78. }