Ejemplo n.º 1
0
func Test_Yellow_2(t *testing.T) {
	expected := "polru"
	actual := Color.Yellow("polru", false)
	if actual != expected {
		t.Errorf("Test failed, expected: '%s', got: '%s'", expected, actual)
	}
}
Ejemplo n.º 2
0
func Test_Yellow_1(t *testing.T) {
	expected := "\x1b[33mpolru\x1b[39;49m"
	actual := Color.Yellow("polru", true)
	if actual != expected {
		t.Errorf("Test failed, expected: '%s', got: '%s'", expected, actual)
	}
}
Ejemplo n.º 3
0
func printSummary(user anaconda.User, color bool) {
	fmt.Print(" ", user.Name)
	fmt.Printf("(%s)", Color.Blue(user.ScreenName, color))
	fmt.Print("     id:", Color.Blue(user.IdStr, color))
	fmt.Print("\n")
	fmt.Print(" ", user.Name)
	if user.GeoEnabled {
		fmt.Printf(" has geolocation %s\n", Color.Green("enabled", color))
	} else {
		fmt.Printf(" has geolocation %s\n", Color.Magenta("disabled", color))
	}
	locale := ""
	location := user.Location
	if "" != location {
		locale += "Location:  " + Color.Green(location, color) + ";     "
	}
	timezone := user.TimeZone
	if "" != timezone {
		locale += "Timezone: " + Color.Green(timezone, color) + ";     "
	}
	language := user.Lang
	if "" != language {
		locale += "Language: " + Color.Green(language, color) + ";"
	}
	if "" != locale {
		fmt.Printf(" %s\n", locale)
	}
	fmt.Printf(" Created: %s\n", Color.Green(user.CreatedAt, color))
	fmt.Printf(" URL: %s\n", Color.Yellow(user.URL, color))
	fmt.Printf(" Profile Image: %s\n", Color.Yellow(user.ProfileImageURL, color))
	fmt.Printf(" %v favorites;     %v friends;     %v followers;\n", user.FriendsCount, user.FavouritesCount, user.FollowersCount)
	fmt.Printf(" Member of %v public lists\n", user.ListedCount)
	numberOfTweets := user.StatusesCount
	fmt.Printf(" Number of Tweets: %v\n", numberOfTweets)
	if numberOfTweets > 0 {
		fmt.Printf(" Most Recent Tweet: %s\n", user.Status.Text)
	}
}
Ejemplo n.º 4
0
func main() {
	namePtr := flag.String("name", "prvn_30", "target's twitter handle")
	count := flag.Int("count", 100, "number of tweets to analyze")
	outputSummary := flag.Bool("summary", true, "summary of the target's account")
	outputGeolocationDate := flag.Bool("loc", false, "target's locations arranged by date")
	outputGeolocationFreq := flag.Bool("loc-freq", false, "target's locations arranged by frequency")
	outputHashtagFreq := flag.Bool("hash-freq", false, "targets's hashtags arranged by frequency")
	outputHashtagDate := flag.Bool("hash", false, "targets's hashtags arranged by date")
	outputMediaFreq := flag.Bool("media-freq", false, "targets's media arranged by frequency")
	outputMediaDate := flag.Bool("media", false, "targets's media arranged by date")
	outputMentionFreq := flag.Bool("mention-freq", false, "targets's user mentions arranged by frequency")
	outputMentionDate := flag.Bool("mention", false, "targets's user mentions arranged by date")
	outputUriFreq := flag.Bool("url-freq", false, "targets's urls arranged by frequency")
	outputUriDate := flag.Bool("url", false, "targets's urls arranged by date")
	outputNoColor := flag.Bool("nocolor", false, "plain output")
	flag.Parse()

	color := !*outputNoColor

	anaconda.SetConsumerKey(apiKey)
	anaconda.SetConsumerSecret(apiSecret)
	api := anaconda.NewTwitterApi(accessToken, accessSecret)

	if *outputSummary {
		user, errGetUser := api.GetUsersShow(*namePtr, nil)
		if errGetUser != nil {
			fmt.Println(errGetUser)
		} else {
			printSummary(user, color)
		}
	}

	if *outputGeolocationFreq || *outputGeolocationDate || *outputHashtagFreq || *outputHashtagDate || *outputMediaFreq || *outputMediaDate || *outputMentionFreq || *outputMentionDate || *outputUriFreq || *outputUriDate {
		v := url.Values{}
		v.Set("screen_name", *namePtr)
		v.Set("count", strconv.Itoa(*count))
		tweetsUnparsed, errTweets := api.GetUserTimeline(v)

		if nil != errTweets {
			fmt.Println(errTweets)
		} else {
			tweets := anacondaTweetsToTweets(tweetsUnparsed)
			if *outputGeolocationDate {
				fmt.Println("\n", Color.Yellow("Date                            Location", color))
				printGeolocationByDate(tweets, color)
			}
			if *outputGeolocationFreq {
				fmt.Println("\n", Color.Yellow("Frequency  Location", color))
				locations := getGeolocationFreq(tweets)
				printEntitiesByFrequency(locations, "", color)
			}
			if *outputHashtagDate {
				fmt.Println("\n", Color.Yellow("Date                           Hashtag", color))
				printHashtagsByDate(tweets, color)
			}
			if *outputHashtagFreq {
				fmt.Println("\n", Color.Yellow("Frequency  Hashtag", color))
				hashtags := getHashtagsFrequency(tweets)
				printEntitiesByFrequency(hashtags, "#", color)
			}
			if *outputMediaDate {
				fmt.Println("\n", Color.Yellow("Date                           Media", color))
				printMediaByDate(tweets, color)
			}
			if *outputMediaFreq {
				fmt.Println("\n", Color.Yellow("Frequency Media", color))
				media := getMediaFrequency(tweets)
				printEntitiesByFrequency(media, "", color)
			}
			if *outputMentionDate {
				fmt.Println("\n", Color.Yellow("Date                           Users Mentioned", color))
				printMentionsByDate(tweets, color)
			}
			if *outputMentionFreq {
				fmt.Println("\n", Color.Yellow("Frequency  Users Mentioned", color))
				mentions := getMentionsFrequency(tweets)
				printEntitiesByFrequency(mentions, "@", color)
			}
			if *outputUriDate {
				fmt.Println("\n", Color.Yellow("Date                           URL", color))
				printMediaByDate(tweets, color)
			}
			if *outputUriFreq {
				fmt.Println("\n", Color.Yellow("Frequency  URL", color))
				uri := getUriFrequency(tweets)
				printEntitiesByFrequency(uri, "", color)
			}
		}
	}
}