示例#1
0
文件: twitter.go 项目: joek/pingu
func main() {
	tux := pingu.NewTux(os.Getenv("TUX_PORT"))
	go tux.Run("5")
	go tux.Run("3")

	anaconda.SetConsumerKey(os.Getenv("TWITTER_CONSUMER_KEY"))
	anaconda.SetConsumerSecret(os.Getenv("TWITTER_CONSUMER_SECRET"))
	api := anaconda.NewTwitterApi(os.Getenv("TWITTER_ACCESS_TOKEN"), os.Getenv("TWITTER_ACCESS_TOKEN_SECRET"))
	// api.SetLogger(anaconda.BasicLogger)

	f := url.Values{}
	f.Add("track", os.Getenv("TWITTER_TRACK_STRING"))
	stream := api.PublicStreamFilter(f)

	fmt.Println("Twitter connected.")

	for t := range stream.C {
		tux.Wave()
		tweet := t.(anaconda.Tweet)
		fmt.Printf("recieved: %#v\n", tweet.Text)
	}
}
示例#2
0
文件: tux.go 项目: joek/pingu
func main() {
	gbot := gobot.NewGobot()

	mqttAdaptor := mqtt.NewMqttAdaptor("server", "tcp://0.0.0.0:1883", "pinguClient")
	tux := pingu.NewTux("/dev/cu.usbmodem1411")

	work := func() {
		mqttAdaptor.On("pingu", func(data []byte) {
			fmt.Println("PINGU!!!")
			tux.Wave()
		})
	}

	robot := gobot.NewRobot("mqttBot",
		[]gobot.Connection{mqttAdaptor},
		work,
	)

	go tux.Run("5")
	go tux.Run("3")
	gbot.AddRobot(robot)

	gbot.Start()
}