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