-
Notifications
You must be signed in to change notification settings - Fork 0
/
long_thread.go
68 lines (59 loc) · 1.38 KB
/
long_thread.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
package main
import (
"clout/models"
"clout/network"
"clout/session"
"encoding/json"
"fmt"
"strings"
"time"
)
// 106579af0baa776bcda80ffea77b3549be64326dfe2bfef9978f28b7211ce9fc
// 0c86890b5955cf28660c91797dc93cfdc12b2e2d4cd45cda4e26635c7cc75a78
func HandleLongThread() {
id := argMap["id"]
if id == "" {
return
}
m := map[string]map[string]bool{}
LoopThruLongThread(id, m)
for k, v := range m {
fmt.Printf("%s was mentioned by %d other users:\n", k, len(v))
for kk, _ := range v {
fmt.Println(" ", kk)
}
}
}
func CheckForContent(username, body string, m map[string]map[string]bool) {
fmt.Println(username)
tokens := strings.Split(body, "\n")
for _, line := range tokens {
tokens = strings.Split(line, " ")
for _, word := range tokens {
if strings.HasPrefix(word, "@") {
tagged := word[1:]
if m[tagged] == nil {
m[tagged] = map[string]bool{}
}
m[tagged][username] = true
}
}
}
}
func LoopThruLongThread(key string, m map[string]map[string]bool) {
offset := int64(0)
pub58 := session.LoggedInPub58()
for {
js := network.GetSinglePostWithOffset(offset, pub58, key)
var ps models.PostStateless
json.Unmarshal([]byte(js), &ps)
if len(ps.PostFound.Comments) == 0 {
break
}
for _, p := range ps.PostFound.Comments {
CheckForContent(p.ProfileEntryResponse.Username, p.Body, m)
}
offset += 20
time.Sleep(time.Second * 1)
}
}