Skip to content

Instantly share code, notes, and snippets.

@nakatanakatana
Last active May 2, 2017 00:52
Show Gist options
  • Save nakatanakatana/859b55ab250860fecded74b11c47a103 to your computer and use it in GitHub Desktop.
Save nakatanakatana/859b55ab250860fecded74b11c47a103 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/ChimeraCoder/anaconda"
"os"
"fmt"
"strings"
"net/url"
)
type Clients map[string] struct{}
func (c Clients) add(ent string) {
c[ent] = struct {}{}
}
func (c Clients) all() []string{
result := make([]string, len(c))
i := 0
for name := range c {
result[i] = name
i++
}
return result
}
func getClientName(source string) string {
s := source
s = strings.Split(s, ">")[1]
s = strings.Split(s, "<")[0]
return s
}
func main() {
consumerKey := os.Getenv("TwitterConsumerKey")
consumerSecret := os.Getenv("TwitterConsumerSecret")
accessToken := os.Getenv("TwitterAccessToken")
accessTokenSecret := os.Getenv("TwitterAccessTokenSecret")
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
v := url.Values{}
v.Set("count", "200")
info := make(map[string]Clients)
tweet, err := api.GetHomeTimeline(v)
if err != nil {
fmt.Println(err)
return
}
for _, t := range tweet{
user := t.User.ScreenName
if _, ok := info[user]; ok {
info[user].add(getClientName(t.Source))
} else {
c := make(Clients)
c.add(getClientName(t.Source))
info[user] = c
}
}
for i := range info {
fmt.Println(i, ":", strings.Join(info[i].all(), ", "))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment