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.

67 lines
1.6 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 printUserFollowsData(user *twitter.User) {
  12. fmt.Print("followers: ")
  13. c.Cyan(strconv.Itoa(user.FollowersCount))
  14. fmt.Print("following: ")
  15. c.Cyan(strconv.Itoa(user.FriendsCount))
  16. }
  17. func unfollowUser(client *twitter.Client, screenName string) {
  18. user, httpResp, _ := client.Friendships.Destroy(&twitter.FriendshipDestroyParams{
  19. ScreenName: screenName,
  20. })
  21. if httpResp.Status != "200 OK" {
  22. c.Red(httpResp.Status)
  23. }
  24. c.Green(user.ScreenName)
  25. }
  26. func getFollowingUsers(client *twitter.Client, user *twitter.User) {
  27. following, httpResp, err := client.Friends.List(&twitter.FriendListParams{
  28. ScreenName: user.ScreenName,
  29. Count: 200,
  30. })
  31. if err != nil {
  32. fmt.Println(err)
  33. }
  34. if httpResp.Status != "200 OK" {
  35. c.Red(httpResp.Status)
  36. }
  37. //fmt.Println(following)
  38. for _, k := range following.Users {
  39. unfollowUser(client, k.ScreenName)
  40. //wait to avoid the twitter api limitation
  41. fmt.Println("waiting 1 min to avoid twitter api limitation")
  42. fmt.Println(time.Now().Local())
  43. time.Sleep(1 * time.Minute)
  44. }
  45. }
  46. func optionUnfollowAll(client *twitter.Client) {
  47. fmt.Println("Getting user data...")
  48. user := getUserData(client)
  49. printUserFollowsData(user)
  50. fmt.Println("")
  51. c.Red("Are you sure you want to unfollow all? [y/n]")
  52. newcommand := bufio.NewReader(os.Stdin)
  53. answer, _ := newcommand.ReadString('\n')
  54. answer = strings.TrimSpace(answer)
  55. switch answer {
  56. case "y":
  57. fmt.Println("ok, you are sure")
  58. getFollowingUsers(client, user)
  59. break
  60. default:
  61. fmt.Println("Operation cancelled")
  62. break
  63. }
  64. }