Пример #1
0
func NewStoryTwitter(member *Member, feed *Feed, tweet anaconda.Tweet) *Story {
	hashtags := []string{}
	for _, hashtag := range tweet.Entities.Hashtags {
		hashtags = append(hashtags, hashtag.Text)
	}

	urls := []string{}
	for _, url := range tweet.Entities.Urls {
		urls = append(urls, url.Url)
	}

	t, err := tweet.CreatedAtTime()
	if err != nil {
		t = time.Now()
	}

	images := []string{}
	for _, media := range tweet.Entities.Media {
		if media.Type == "image" {
			images = append(images, media.Media_url)
		}
	}
	score := tweet.FavoriteCount + (2 * tweet.RetweetCount)
	sourceURL := fmt.Sprintf("http://twitter.com/%s/status/%s", tweet.User.ScreenName, tweet.IdStr)
	return &Story{
		MemberID:       member.ID,
		MemberName:     member.Name,
		FeedID:         feed.ID,
		FeedIdentifier: feed.Identifier,
		Timestamp:      milli.Timestamp(t),
		Body:           tweet.Text,
		FeedType:       string(FeedTypeTwitter),
		SourceURL:      sourceURL,
		SourceID:       tweet.IdStr,
		Latitude:       0.0,
		Longitude:      0.0,
		Score:          float64(score),
		LinksRaw:       strings.Join(urls, ","),
		HashtagsRaw:    strings.Join(hashtags, ","),
		ImagesRaw:      strings.Join(images, ","),
	}
}
Пример #2
0
func (c *TwitterCrawler) GetTimelines(account string, strictrange bool) timelinesTweets {
	since := c.configuration.FetchFrom

	myTweets := make(timelinesTweets)
	var max_id int64
	var tweet anaconda.Tweet
	searchresult, _ := c.api.GetUsersShow(account, nil)
	v := url.Values{}
	var timeline []anaconda.Tweet
	//var Tweettime string
	v.Set("user_id", searchresult.IdStr)
	v.Set("count", "1") //getting twitter first tweet
	timeline, _ = c.api.GetUserTimeline(v)
	max_id = timeline[0].Id // putting it as max_id
	time, _ := timeline[0].CreatedAtTime()

	for time.Unix() >= since { //until we don't exceed our range of interest

		v = url.Values{}
		v.Set("user_id", searchresult.IdStr)
		v.Set("count", "200")
		v.Set("max_id", strconv.FormatInt(max_id, 10))
		timeline, _ = c.api.GetUserTimeline(v)
		for _, tweet = range timeline {

			time, _ = tweet.CreatedAtTime()
			if strictrange && time.Unix() >= since {
				myTweets[tweet.IdStr] = tweet
			} else {
				myTweets[tweet.IdStr] = tweet
			}
			//Tweettime = fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d", time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second())
			//log.Info("\tTweet @ " + Tweettime + " : " + tweet.IdStr)
			max_id = tweet.Id - 1
		}
		//log.Info("\tFinished reading timeslice for " + account)
	}
	//log.Info("\tFinished reading timeline for " + account)

	return myTweets

}
Пример #3
0
func (c *TwitterCrawler) Search(searchString string) searchTweets {
	since := c.configuration.FetchFrom
	myTweets := make(searchTweets)
	var max_id int64
	var tweet anaconda.Tweet
	v := url.Values{}
	var Tweettime string
	var myTime time.Time
	v.Set("count", "200")

	searchResult, _ := c.api.GetSearch(searchString, v)
	for _, tweet := range searchResult.Statuses {
		myTweets[tweet.IdStr] = tweet
		fmt.Println(tweet.Text)
		myTime, _ = tweet.CreatedAtTime()

	}
	max_id = searchResult.Metadata.MaxId // putting it as max_id
	for myTime.Unix() >= since {         //until we don't exceed our range of interest
		v = url.Values{}
		v.Set("count", "200")
		v.Set("max_id", strconv.FormatInt(max_id, 10))

		searchResult, _ := c.api.GetSearch(searchString, v)

		for _, tweet = range searchResult.Statuses {
			if myTime.Unix() >= since {
				myTweets[tweet.IdStr] = tweet
			}
			fmt.Println(tweet.Text)
			myTime, _ = tweet.CreatedAtTime()

			Tweettime = fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d", myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second())
			user_tweet := tweet.User.ScreenName
			fmt.Println("[" + user_tweet + "] Tweet @ " + Tweettime + " : " + tweet.IdStr)
			max_id = tweet.Id - 1
		}

	}
	return myTweets

}
Пример #4
0
func GetTimelines(api *anaconda.TwitterApi, account string, since int64) timelinesTweets {
	myTweets := make(timelinesTweets)
	var max_id int64
	var tweet anaconda.Tweet
	searchresult, _ := api.GetUsersShow(account, nil)
	v := url.Values{}
	var timeline []anaconda.Tweet
	var Tweettime string
	v.Set("user_id", searchresult.IdStr)
	v.Set("count", "1") //getting twitter first tweet
	timeline, _ = api.GetUserTimeline(v)
	max_id = timeline[0].Id // putting it as max_id
	time, _ := timeline[0].CreatedAtTime()

	for time.Unix() >= since { //until we don't exceed our range of interest

		v = url.Values{}
		v.Set("user_id", searchresult.IdStr)
		v.Set("count", "200")
		v.Set("max_id", strconv.FormatInt(max_id, 10))
		timeline, _ = api.GetUserTimeline(v)
		for _, tweet = range timeline {

			time, _ = tweet.CreatedAtTime()
			myTweets[tweet.IdStr] = tweet
			Tweettime = fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d", time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second())
			log.Info("\tTweet @ " + Tweettime + " : " + tweet.IdStr)
			max_id = tweet.Id
		}
		log.Info("\tFinished reading timeslice for " + account)
	}
	log.Info("\tFinished reading timeline for " + account)

	return myTweets

}