Example #1
0
func decode(conn *twitterstream.Connection) {
	for {
		if tweet, err := conn.Next(); err == nil {
			log.Println("%s said: %s", tweet.User.ScreenName, tweet.Text)
		} else {
			log.Printf("Failed decoding tweet: %s", err)
			return
		}
	}
}
Example #2
0
func decode(conn *twitterstream.Connection) {
	for {
		if tweet, err := conn.Next(); err == nil {
			addTweet(tweet)
		} else {
			fmt.Println("Failed decoding tweet: %s", err)
			log.Printf("Failed decoding tweet: %s", err)
			return
		}
	}
}
Example #3
0
func kanojoru(conn *twitterstream.Connection) {
	for {
		tweet, err := conn.Next()
		if err != nil {
			return
		}
		if !canKanojonize(tweet) {
			continue
		}

		text := tweet.Text
		kanojonized := kanojonize(text)
		post(kanojonized)
	}
}
Example #4
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
		}
	}
}
Example #5
0
func decode(conn *twitterstream.Connection) {
	for {
		if tweet, err := conn.Next(); err == nil {
			ct.ChangeColor(ct.Red, true, ct.None, false)
			fmt.Print(timeNow, " ")
			ct.ChangeColor(ct.Yellow, true, ct.None, false)
			fmt.Print(tweet.User.ScreenName, ": ")
			ct.ChangeColor(ct.Cyan, true, ct.None, false)
			fmt.Println(tweet.Text)
		} else {
			log.Fatal(timeNow, "Failed decoding tweet: %s", err)
			return
		}
	}
}
func decodeTweets(conn *twitterstream.Connection) {
	var tweet *Tweet
	for {
		if retrievedTweet, err := conn.Next(); err == nil {
			log.Printf("New Tweet: %s\n", retrievedTweet.Text)
			tweet = new(Tweet)
			for _, hashtag := range retrievedTweet.Entities.Hashtags {
				tweet.Hashtags = append(tweet.Hashtags, hashtag.Text)
			}
			for _, mention := range retrievedTweet.Entities.Mentions {
				tweet.Mentions = append(tweet.Mentions, mention.ScreenName)
			}
			tweet.Text = retrievedTweet.Text
			tweet.Name = retrievedTweet.User.Name
			tweet.ScreenName = retrievedTweet.User.ScreenName

			tweets <- tweet
		} else {
			log.Printf("decoding tweet failed: %s", err)
			return
		}
	}
}
Example #7
0
// read each message from twitter
func (d *Twitter) readTwitter() (err error) {

	d.client = twitterstream.NewClient(d.consumerKey, d.consumerSecret, d.accessToken, d.accessSecret)

	for {
		var conn *twitterstream.Connection

		if d.keywords == "" {
			log.Println("Sampling Twitter")
			conn, err = d.client.Sample()
		} else {
			log.Printf("Tracking %s", d.keywords)
			conn, err = d.client.Track(d.keywords)
		}

		if err == nil {

			for {
				if tweet, err := conn.Next(); err == nil {
					doc := structs.Map(tweet)
					msg := message.NewMsg(message.Insert, doc)
					if msg != nil {
						d.pipe.Send(msg)
					} else {
						break
					}
				} else {
					break
				}
			}
		} else {
			log.Println("Sleeping before reconnecting")
			time.Sleep(time.Duration(10 * time.Second))
		}
	}
}
Example #8
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
}