本文整理汇总了Golang中github.com/darkhelmet/twitterstream.Connection类的典型用法代码示例。如果您正苦于以下问题:Golang Connection类的具体用法?Golang Connection怎么用?Golang Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decode
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
}
}
}
示例2: decode
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
}
}
}
示例3: kanojoru
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)
}
}
示例4: decodeTweets
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
}
}
}
示例5: decode
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
}
}
}
示例6: decodeTweets
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
}
}
}
示例7: readTwitter
// 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))
}
}
}
示例8: decodeTweets
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
}