예제 #1
0
// Every tweet is its own feed item
func CreateIndividualFeed(conf config.Config, tweets []twitter.Tweet) *feeds.Feed {
	feed := createFeedHeader()

	for _, tweet := range tweets {
		parsedTweetText := parser.ParseTweetText(tweet)

		if filter.IsTweetFiltered(tweet, conf, parsedTweetText) {
			continue
		}

		titleLimit := 60
		if len(tweet.Text) < 60 {
			titleLimit = len(tweet.Text)
		}
		item := &feeds.Item{
			// TODO: check if slicing a string with non ascii chars will fail/scramble the text
			Title:       fmt.Sprintf("%s: %s...", tweet.User.Name, tweet.Text[:titleLimit]),
			Link:        &feeds.Link{Href: parser.GetTweetUrl(tweet)},
			Description: parsedTweetText,
			Author:      &feeds.Author{Name: tweet.User.Name, Email: tweet.User.ScreenName},
			Created:     parser.ConvertTwitterTime(tweet.CreatedAt),
			Id:          tweet.IDStr,
		}
		feed.Add(item)
	}

	return feed
}
예제 #2
0
// sort tweet into hour segments & author
// Example:
// 		segment of  6 = 4x  6hour blocks a day
//	 	segment of 12 = 2x 12hour blocks a day
func sortTweetsIntoHourSegments(tweets []twitter.Tweet, segmentSize int) map[string]map[string]Tweets {
	// first string is the date, second the author
	var sortedList map[string]map[string]Tweets
	sortedList = make(map[string]map[string]Tweets)
	for _, tweet := range tweets {
		author := tweet.User.ScreenName
		tweetDate := parser.ConvertTwitterTime(tweet.CreatedAt)
		hourBlock := strconv.Itoa(tweetDate.Hour() / segmentSize)
		timeSegment := tweetDate.Format("2006-01-02") + "-" + hourBlock

		if sortedList[timeSegment] == nil {
			sortedList[timeSegment] = make(map[string]Tweets)
		}
		sortedList[timeSegment][author] = append(sortedList[timeSegment][author], tweet)
	}

	return sortedList
}