argos/optionAnalyzeTweet.go
optionAnalyzeTweet.goRaw
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "os"
7 "sort"
8 "strconv"
9 "strings"
10
11 "github.com/dghubble/go-twitter/twitter"
12)
13
14type DateRT struct {
15 Retweets []twitter.Tweet
16 Date string
17}
18
19func optionAnalyzeTweet(client *twitter.Client) {
20 newcommand := bufio.NewReader(os.Stdin)
21 fmt.Print("enter link of the tweet: ")
22 link, _ := newcommand.ReadString('\n')
23 link = strings.TrimSpace(link)
24 fmt.Print("link selected: ")
25 c.Cyan(link)
26 fmt.Println("-----------------------")
27 linkParam := strings.Split(link, "/")
28 tweetIdStr := linkParam[len(linkParam)-1]
29 c.Cyan(tweetIdStr)
30 tweetId, err := strconv.ParseInt(tweetIdStr, 10, 64)
31 if err != nil {
32 fmt.Println(err)
33 }
34
35 tweet, _, err := client.Statuses.Show(tweetId, nil)
36 if err != nil {
37 fmt.Println(err)
38 }
39 fmt.Print("tweet text: ")
40 c.Yellow(tweet.Text)
41
42 retweets := getRetweets(client, tweetId)
43
44 var dates = make(map[string]DateRT)
45 for _, retweet := range retweets {
46 retws := dates[retweet.CreatedAt].Retweets
47 retws = append(retws, retweet)
48 var currDate DateRT
49 currDate.Retweets = retws
50 currDate.Date = retweet.CreatedAt
51 dates[retweet.CreatedAt] = currDate
52 }
53 fmt.Println("total of " + strconv.Itoa(len(retweets)) + " retweets")
54
55 //puts the map into a slice, to easy sort
56 var arrayDates []DateRT
57 for _, v := range dates {
58 arrayDates = append(arrayDates, v)
59 }
60
61 fmt.Println("")
62 c.Cyan("Showing accounts that retweeted at the same exact time (they are possible Bots) and the source the RT were made:")
63
64 //sort the slice
65 sort.Slice(arrayDates, func(i, j int) bool {
66 return len(arrayDates[i].Retweets) < len(arrayDates[j].Retweets)
67 })
68 //print the sorted slice
69 for _, v := range arrayDates {
70 if len(v.Retweets) > 1 {
71 printDateRT(v)
72 }
73 }
74 fmt.Println("")
75 c.Purple("Warning: Twitter API only gives the last 100 Retweets")
76}
77func printDateRT(v DateRT) {
78 fmt.Print("\x1b[32;1m" + v.Date + "\x1b[0m")
79 fmt.Println(" " + strconv.Itoa(len(v.Retweets)) + " Retweets at this date:")
80 for _, retweet := range v.Retweets {
81 source := strings.Split(strings.Split(retweet.Source, ">")[1], "<")[0]
82 if len(v.Retweets) > 1 {
83 fmt.Print("\x1b[31;1m") //red
84 }
85 fmt.Print(" @" + retweet.User.ScreenName)
86 fmt.Print("\x1b[0m") //defaultColor
87 fmt.Print(" (ID: ")
88 fmt.Print("\x1b[31;1m" + retweet.User.IDStr + "\x1b[0m)")
89 fmt.Print(", source: \x1b[33;1m" + source + "\x1b[0m")
90 fmt.Print(", user created at: \x1b[32;1m" + retweet.User.CreatedAt + "\x1b[0m,")
91
92 fmt.Print(" \x1b[34;1m" + strconv.Itoa(retweet.User.FollowersCount) + "\x1b[0m followers")
93 fmt.Print(", \x1b[34;1m" + strconv.Itoa(retweet.User.FriendsCount) + "\x1b[0m following")
94 fmt.Println("")
95 }
96 fmt.Println("")
97
98}