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.

72 lines
1.7 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. type DateRT struct {
  11. Retweets []twitter.Tweet
  12. }
  13. func optionAnalyzeTweet(client *twitter.Client) {
  14. newcommand := bufio.NewReader(os.Stdin)
  15. fmt.Print("enter link of the tweet: ")
  16. link, _ := newcommand.ReadString('\n')
  17. link = strings.TrimSpace(link)
  18. fmt.Print("link selected: ")
  19. c.Cyan(link)
  20. fmt.Println("-----------------------")
  21. linkParam := strings.Split(link, "/")
  22. tweetIdStr := linkParam[len(linkParam)-1]
  23. c.Cyan(tweetIdStr)
  24. tweetId, err := strconv.ParseInt(tweetIdStr, 10, 64)
  25. if err != nil {
  26. fmt.Println(err)
  27. }
  28. tweet, _, err := client.Statuses.Show(tweetId, nil)
  29. if err != nil {
  30. fmt.Println(err)
  31. }
  32. fmt.Print("tweet text: ")
  33. c.Yellow(tweet.Text)
  34. retweets := getRetweets(client, tweetId)
  35. var dates = make(map[string]DateRT)
  36. for _, retweet := range retweets {
  37. retws := dates[retweet.CreatedAt].Retweets
  38. retws = append(retws, retweet)
  39. var currDate DateRT
  40. currDate.Retweets = retws
  41. dates[retweet.CreatedAt] = currDate
  42. }
  43. fmt.Print("total of: ")
  44. fmt.Println(len(retweets))
  45. for k, v := range dates {
  46. printDateRT(k, v)
  47. }
  48. c.Purple("Warning: Twitter API only gives the last 100 Retweets")
  49. }
  50. func printDateRT(k string, v DateRT) {
  51. fmt.Print("\x1b[32;1m" + k + "\x1b[0m")
  52. fmt.Println(" " + strconv.Itoa(len(v.Retweets)) + " Retweets at this date:")
  53. for _, retweet := range v.Retweets {
  54. source := strings.Split(strings.Split(retweet.Source, ">")[1], "<")[0]
  55. if len(v.Retweets) > 1 {
  56. fmt.Print("\x1b[31;1m") //red
  57. }
  58. fmt.Print(" @" + retweet.User.ScreenName)
  59. fmt.Print("\x1b[0m") //defaultColor
  60. fmt.Println(", source: " + source)
  61. }
  62. }