本文整理汇总了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
}
}
}
开发者ID:hasanozgan,项目名称:zamazingo,代码行数:10,代码来源:stream.go
示例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
}
}
}
开发者ID:StephaneC,项目名称:GoTweets,代码行数:11,代码来源:main.go
示例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)
}
}
开发者ID:hisaichi5518,项目名称:yuriko,代码行数:15,代码来源:commands.go
示例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
}
}
}
开发者ID:hut8,项目名称:twitterstream,代码行数:15,代码来源:twimgd.go
示例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
}
}
}
开发者ID:Chubik,项目名称:twitterStream,代码行数:15,代码来源:twitterstream.go
示例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
}
}
}
开发者ID:johnzan,项目名称:TwitterStreamingExample,代码行数:23,代码来源:golang_medellin.go
示例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))
}
}
}
开发者ID:codepope,项目名称:transporter,代码行数:37,代码来源:twitter.go
示例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
}
开发者ID:bulkan,项目名称:queshuns,代码行数:24,代码来源:daemon.go
注:本文中的github.com/darkhelmet/twitterstream.Connection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论