The following can be saved as main.go. After you update the EDITME settings and build the executable it can be used as a continuous external collector.
package main
import (
"fmt"
"log"
"net/url"
"strconv"
"time"
"github.com/ChimeraCoder/anaconda"
)
func main() {
anaconda.SetConsumerKey("EDITME")
anaconda.SetConsumerSecret("EDITME")
api := anaconda.NewTwitterApi("EDITME", "EDITME")
v := url.Values{}
sr, err := api.GetSearch("stackoverflow", nil)
if err != nil {
log.Println(err)
}
var since_id int64 = 0
for _, tweet := range sr {
if tweet.Id > since_id {
since_id = tweet.Id
}
}
count := 0
for {
now := time.Now().Unix()
v.Set("result_type", "recent")
v.Set("since_id", strconv.FormatInt(since_id, 10))
sr, err := api.GetSearch("stackoverflow", nil)
if err != nil {
log.Println(err)
}
for _, tweet := range sr {
if tweet.Id > since_id {
count += 1
since_id = tweet.Id
}
}
fmt.Println("twitter.tweet_count", now, count, "query=stackoverflow")
time.Sleep(time.Second * 30)
}
}