-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfollow.go
48 lines (44 loc) · 1.19 KB
/
follow.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
package cloutcli
import (
"encoding/json"
"fmt"
"time"
"github.com/andrewarrow/cloutcli/lib"
"github.com/andrewarrow/cloutcli/network"
)
func GetNumFollowers(pub58, username string) int64 {
js := network.GetFollowsStateless(pub58, username, "")
var pktpe lib.PublicKeyToProfileEntry
json.Unmarshal([]byte(js), &pktpe)
return pktpe.NumFollowers
}
func LoopThruAllFollowing(pub58, username string, limit int) []string {
last := ""
js := network.GetFollowsStateless(pub58, username, last)
var pktpe lib.PublicKeyToProfileEntry
json.Unmarshal([]byte(js), &pktpe)
NumFollowers := pktpe.NumFollowers
total := map[string]bool{}
bigList := []string{}
fmt.Println("Getting all", pktpe.NumFollowers, "...")
for {
for key, v := range pktpe.PublicKeyToProfileEntry {
last = key
if total[v.Username] == false {
total[v.Username] = true
bigList = append(bigList, v.Username)
}
}
if len(bigList) >= limit && limit != 0 {
break
}
if len(total) >= int(NumFollowers) {
break
}
fmt.Println("got", len(bigList), "out of", NumFollowers)
time.Sleep(time.Second * 1)
js := network.GetFollowsStateless(pub58, username, last)
json.Unmarshal([]byte(js), &pktpe)
}
return bigList
}