Example #1
0
func Serve() {

	tl, err := twistream.New(
		"https://userstream.twitter.com/1.1/user.json",
		config.V.Twitter.Consumer.Key,
		config.V.Twitter.Consumer.Secret,
		config.V.Twitter.Bot.AccessToken,
		config.V.Twitter.Bot.AccessTokenSecret,
	)

	if err != nil {
		log.Fatalf("failed to init timeline: %v", err)
	}

	routes.LoadHandlers()

	// {{{ TODO: あとでなおす. filterとかでかっちょよくする
	mongosession, err := mgo.Dial(config.MongoURI())
	if err != nil {
		log.Fatalf("failed to connect mongodb: %v", err)
	}
	handlers.MongoSession = mongosession
	// }}}

	routes.Listen(tl)
}
Example #2
0
func main() {
	var fp *os.File
	var err error
	fp, err = os.Open("/etc/pass/twi.txt")
	if err != nil {
		panic(err)
	}
	defer fp.Close()

	scanner := bufio.NewScanner(fp)

	scanner.Scan()
	consumer_key := scanner.Text()
	scanner.Scan()
	consumer_secret := scanner.Text()
	scanner.Scan()
	accesstoken := scanner.Text()
	scanner.Scan()
	accesstoken_secret := scanner.Text()

	anaconda.SetConsumerKey(consumer_key)
	anaconda.SetConsumerSecret(consumer_secret)
	//api := anaconda.NewTwitterApi(accesstoken, accesstoken_secret)

	if err := scanner.Err(); err != nil {
		panic(err)
	}

	//	tweet, err := api.PostTweet("test tweet2", nil)
	//	fmt.Println(tweet)

	timeline, _ := twistream.New(
		"https://userstream.twitter.com/1.1/user.json",
		consumer_key,
		consumer_secret,
		accesstoken,
		accesstoken_secret,
	)

	for {
		status := <-timeline.Listen()
		fmt.Println(status.User.Name + "  @" + status.User.ScreenName)
		fmt.Println(status.Text)
		fmt.Println()
	}
}
Example #3
0
func main() {
	c := readConf()
	timeline, _ := twistream.New(
		"https://userstream.twitter.com/1.1/user.json",
		c.ConsumerKey,
		c.ConsumerSelect,
		c.AccessToken,
		c.AccessTokenSelect,
	)

	anaconda.SetConsumerKey(c.ConsumerKey)
	anaconda.SetConsumerSecret(c.ConsumerSelect)
	api := anaconda.NewTwitterApi(c.AccessToken, c.AccessTokenSelect)
	uptime := int64(0)

	// Listen timeline
	for {
		status := <-timeline.Listen()
		if strings.Contains(status.Text, "レイバンの") {
			api.DeleteTweet(status.Id, true)
			uptime = alert(uptime)
		}
	}
}