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.

66 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. for _, k := range following.Users {
  38. unfollowUser(client, k.ScreenName)
  39. //wait to avoid the twitter api limitation
  40. fmt.Println("waiting 1 min to avoid twitter api limitation")
  41. fmt.Println(time.Now().Local())
  42. time.Sleep(1 * time.Minute)
  43. }
  44. }
  45. func optionUnfollowAll(client *twitter.Client) {
  46. fmt.Println("Getting user data...")
  47. user := getUserData(client)
  48. printUserFollowsData(user)
  49. fmt.Println("")
  50. c.Red("Are you sure you want to unfollow all? [y/n]")
  51. newcommand := bufio.NewReader(os.Stdin)
  52. answer, _ := newcommand.ReadString('\n')
  53. answer = strings.TrimSpace(answer)
  54. switch answer {
  55. case "y":
  56. fmt.Println("ok, you are sure")
  57. getFollowingUsers(client, user)
  58. break
  59. default:
  60. fmt.Println("Operation cancelled")
  61. break
  62. }
  63. }