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