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.8 KiB

7 years ago
7 years ago
  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 optionAnalyzeUserTweets(client *twitter.Client) {
  11. newcommand := bufio.NewReader(os.Stdin)
  12. fmt.Print("enter username: @")
  13. username, _ := newcommand.ReadString('\n')
  14. username = strings.TrimSpace(username)
  15. fmt.Print("user selected: ")
  16. c.Cyan("@" + username)
  17. fmt.Println("-----------------------")
  18. //get tweets
  19. tweets := getTweets(client, username, iterationsCount)
  20. if len(tweets) == 0 {
  21. fmt.Println("User @" + username + " does not have tweets")
  22. return
  23. }
  24. //now analyze words and dates
  25. fmt.Println("Word frequency (more than " + strconv.Itoa(minNumWords) + " times):")
  26. words := analyzeWords(tweets)
  27. fmt.Println("Hashtags used (more than " + strconv.Itoa(minNumHashtag) + " times): ")
  28. hashtags := analyzeHashtags(tweets, words)
  29. printSortedMapStringInt(hashtags, minNumHashtag)
  30. fmt.Println("")
  31. fmt.Println("Interactions with other users (more than " + strconv.Itoa(minNumUserInteractions) + " times): ")
  32. userInteractions := analyzeUserInteractions(tweets, words)
  33. printSortedMapStringInt(userInteractions, minNumUserInteractions)
  34. fmt.Println("")
  35. analyzeDates(tweets)
  36. fmt.Println("")
  37. fmt.Println("Devices:")
  38. sources := analyzeSource(tweets)
  39. for k, v := range sources {
  40. fmt.Print("\x1b[32;1m") //cyan
  41. fmt.Print(k + ": ")
  42. fmt.Print("\x1b[0m") //defaultColor
  43. fmt.Println(strconv.Itoa(v) + "tw ")
  44. }
  45. fmt.Println(" ")
  46. fmt.Print("first tweet analyzed: ")
  47. fmt.Println(tweets[len(tweets)-1].CreatedAt)
  48. fmt.Print("last tweet analyzed: ")
  49. fmt.Println(tweets[0].CreatedAt)
  50. fmt.Println(" ")
  51. fmt.Println("Total of " + strconv.Itoa(len(tweets)) + " tweets analyzed")
  52. fmt.Println(" ")
  53. fmt.Print("User @")
  54. c.Cyan(username)
  55. fmt.Println(" analysis finished")
  56. }