-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_stream.go
73 lines (60 loc) · 1.53 KB
/
search_stream.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
67
68
69
70
71
72
73
package collector
import (
"log"
"time"
"github.com/dghubble/go-twitter/twitter"
"github.com/xarantolus/rfa-launch-bot/util"
)
// SearchStream checks out tweets from a large area around Augsburg
func SearchStream(client *twitter.Client, tweetChan chan<- TweetWrapper) {
defer panic("search stream ended even though it never should")
var backoff int = 1
for {
s, err := client.Streams.Filter(&twitter.StreamFilterParams{
Track: []string{
"rocket factory augsburg",
"rocketfactory augsburg",
"rocketfactoryaugsburg",
"rfa_space",
"rfa one",
"rfa1 ",
"rfa 1 ",
"rfa launcher",
"rocket factory one",
"rocket factory launcher",
"esrange space center",
"helix engine",
},
FilterLevel: "none",
})
if util.LogError(err, "search stream") {
goto sleep
}
log.Println("[Twitter] Connected to search stream")
// Stream all tweets and serve them to the channel
for m := range s.Messages {
backoff = 1
t, ok := m.(*twitter.Tweet)
if !ok || t == nil {
continue
}
// If we have truncated text, we try to get the whole tweet
if t.Truncated {
t, _, err = client.Statuses.Show(t.ID, &twitter.StatusShowParams{
TweetMode: "extended",
})
if err != nil {
continue
}
}
tweetChan <- TweetWrapper{
Source: TweetSourceSearchStream,
Tweet: *t,
}
}
backoff *= 2
log.Printf("[Twitter] Search stream ended for some reason, trying again in %d seconds", backoff*5)
sleep:
time.Sleep(time.Duration(backoff) * 5 * time.Second)
}
}