Exemplo n.º 1
0
func decodeTweets(conn *twitterstream.Connection) {
	for {
		if tweet, err := conn.Next(); err == nil {
			for _, medium := range tweet.Entities.Media {
				if download(medium.MediaUrl) {
					messages <- []byte(medium.MediaUrl)
				}
			}
		} else {
			log.Printf("decoding tweet failed: %s", err)
			conn.Close()
			return
		}
	}
}
Exemplo n.º 2
0
func decodeTweets(conn *twitterstream.Connection, messages <-chan bool) bool {
	stopMsg := false
	for !stopMsg {
		select {
		case stopMsg = <-messages:
			log.Printf("got stop message")
			break
		default:
			if tweet, err := conn.Next(); err == nil {
				if tweet.InReplyToScreenName == nil && len(tweet.Text) > 0 && !strings.Contains(tweet.Text, "@") && strings.HasSuffix(tweet.Text, "?") {
					pushToRedis(tweet)
					//time.Sleep(time.Duration(5 * time.Second))
				}

			} else {
				log.Printf("decoding tweet failed: %s", err)
				conn.Close()
			}
		}
	}

	log.Printf("here1")
	return true
}