arnaucube
arnaucube/argosPublic Self-hosted repository
argos/optionGetUserTweets.go
optionGetUserTweets.goRaw
 1package main
 2
 3import (
 4	"bufio"
 5	"fmt"
 6	"os"
 7	"strconv"
 8	"strings"
 9
10	"github.com/dghubble/go-twitter/twitter"
11)
12
13func getTweets(client *twitter.Client, username string, iterations int) []twitter.Tweet {
14	var tweets []twitter.Tweet
15	var maxid int64
16	for i := 0; i < iterations; i++ {
17		tweetsRaw, _, _ := client.Timelines.UserTimeline(&twitter.UserTimelineParams{
18			ScreenName: username,
19			Count:      200,
20			MaxID:      maxid,
21		})
22		//if no tweets, stop getting tweets
23		if len(tweetsRaw) == 0 {
24			break
25		}
26		maxid = tweetsRaw[len(tweetsRaw)-1].ID
27
28		for _, v := range tweetsRaw {
29			tweets = append(tweets, v)
30		}
31	}
32
33	return tweets
34}
35func optionGetUserTweets(client *twitter.Client) {
36	newcommand := bufio.NewReader(os.Stdin)
37	fmt.Print("enter username: @")
38	username, _ := newcommand.ReadString('\n')
39	username = strings.TrimSpace(username)
40	fmt.Print("user selected: ")
41	c.Cyan("@" + username)
42	fmt.Println("-----------------------")
43
44	//get tweets
45	tweets := getTweets(client, username, iterationsCount)
46
47	if len(tweets) == 0 {
48		fmt.Println("User @" + username + " does not have tweets")
49		return
50	}
51	//now analyze words and dates
52	fmt.Println("Word frequency (more than " + strconv.Itoa(minNumWords) + " times):")
53	words := analyzeWords(tweets)
54
55	fmt.Println("Hashtags used (more than " + strconv.Itoa(minNumHashtag) + " times): ")
56	hashtags := analyzeHashtags(tweets, words)
57	printSortedMapStringInt(hashtags, minNumHashtag)
58	fmt.Println("")
59
60	fmt.Println("Interactions with other users (more than " + strconv.Itoa(minNumUserInteractions) + " times): ")
61	userInteractions := analyzeUserInteractions(tweets, words)
62	printSortedMapStringInt(userInteractions, minNumUserInteractions)
63	fmt.Println("")
64
65	analyzeDates(tweets)
66	fmt.Println("")
67	fmt.Println("Devices:")
68	sources := analyzeSource(tweets)
69	for k, v := range sources {
70		fmt.Print("\x1b[32;1m") //cyan
71		fmt.Print(k + ": ")
72		fmt.Print("\x1b[0m") //defaultColor
73		fmt.Println(strconv.Itoa(v) + "tw	")
74	}
75
76	fmt.Println(" ")
77	fmt.Print("first tweet analyzed: ")
78	fmt.Println(tweets[len(tweets)-1].CreatedAt)
79	fmt.Print("last tweet analyzed: ")
80	fmt.Println(tweets[0].CreatedAt)
81
82	fmt.Println(" ")
83	fmt.Println("Total of " + strconv.Itoa(len(tweets)) + " tweets analyzed")
84	fmt.Println(" ")
85	fmt.Print("User @")
86	c.Cyan(username)
87	fmt.Println(" analysis finished")
88}