-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrending.go
44 lines (37 loc) · 954 Bytes
/
trending.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
package main
import (
"github.com/garyburd/redigo/redis"
"github.com/google/go-github/github"
"github.com/hugbotme/hug-go/twitter"
"log"
"time"
)
func QueueTrendingRepositoryWhenIamBored(hugs chan twitter.Hug, lastTweet *time.Time, gh *github.Client, red redis.Conn) {
timeToTick := time.Duration(15) * time.Minute
for {
ticker := time.NewTicker(timeToTick)
<-ticker.C
if time.Since(*lastTweet) < timeToTick {
timeToTick = timeToTick - time.Since(*lastTweet)
} else {
timeToTick = time.Duration(15) * time.Minute
QueueTrendingTopic(hugs, gh, red)
}
}
}
func QueueTrendingTopic(hugs chan twitter.Hug, gh *github.Client, redisClient redis.Conn) {
url, err := redis.String(redisClient.Do("SPOP", "hug:bored-urls"))
if err != nil {
log.Println(err)
return
}
if len(url) == 0 {
log.Println("Trending topics: No topics in Redis")
return
}
toHug := twitter.Hug{
TweetID: "",
URL: url,
}
hugs <- toHug
}