-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (51 loc) · 1.45 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"github.com/ChimeraCoder/anaconda"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"net/url"
"os"
)
type logger struct {
*logrus.Logger
}
func main() {
err := godotenv.Load()
if err != nil {
logrus.Fatal("Failed to load .env file")
}
var (
consumerKey = os.Getenv("CONSUMER_KEY")
consumerSecret = os.Getenv("CONSUMER_SECRET")
accessToken = os.Getenv("ACCESS_TOKEN")
accessTokenSecret = os.Getenv("ACCESS_TOKEN_SECRET")
)
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
log := &logger{logrus.New()}
api.SetLogger(log)
stream := api.PublicStreamFilter(url.Values{
"track": []string{"#golang, #Golang, #GoprogrammingLanguage"},
})
defer stream.Stop()
for v := range stream.C {
t, ok := v.(anaconda.Tweet)
if !ok {
logrus.Warningf("Unexpeted value: %T", v)
continue
}
if t.RetweetedStatus != nil {
continue
}
_, err := api.Retweet(t.Id, false)
if err != nil{
logrus.Errorf("Failed to Retweet %d: %v", t.Id, err)
}
logrus.Infof("Retweeted: %d", t.Id)
}
}
func (log *logger) Critical(args ...interface{}) { log.Error(args...) }
func (log *logger) Criticalf(format string, args ...interface{}) { log.Errorf(format, args...) }
func (log *logger) Notice(args ...interface{}) { log.Info(args...) }
func (log *logger) Noticef(format string, args ...interface{}) { log.Infof(format, args...) }