當前位置: 首頁>>代碼示例>>Golang>>正文


Golang twitterstream.Connection類代碼示例

本文整理匯總了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;未經允許,請勿轉載。