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.

65 lines
1.6 KiB

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