-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsniff.go
43 lines (34 loc) · 917 Bytes
/
sniff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tweety
import (
"flag"
"net/url"
"github.com/ChimeraCoder/anaconda"
"github.com/yanzay/log"
)
// Sniff listen tweets that contain the given word.
// Inspired by #JustForFunc of Francesc Campoy (https://www.youtube.com/c/justforfunc)
func (t *Tweety) Sniff(args []string) {
fs := flag.NewFlagSet("sniff", flag.ExitOnError)
word := fs.String("word", "", "word to sniff in twitter stream.")
fs.Parse(args)
if fs.NArg() != 0 || *word == "" {
fs.Usage()
return
}
log.Infof("\nListening to messages containing: %s\n", *word)
stream := t.api.PublicStreamFilter(url.Values{
"track": []string{*word},
})
defer stream.Stop()
for v := range stream.C {
t, ok := v.(anaconda.Tweet)
if !ok {
log.Warningf("received unexpected value of type %T", v)
continue
}
if t.RetweetedStatus != nil {
continue
}
log.Infof("\nUser: %s | ID: %d\n%s\n\n", t.User.Name, t.Id, t.Text)
}
}