-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotword_sm.go
More file actions
49 lines (41 loc) · 1.2 KB
/
Copy pathhotword_sm.go
File metadata and controls
49 lines (41 loc) · 1.2 KB
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
package finder
import (
"crypto/tls"
"errors"
"net/http"
"time"
"github.com/parnurzeal/gorequest"
"github.com/phuslu/log"
"github.com/tidwall/gjson"
)
func SmHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error) {
var hwrs []*HotWordResult
log.Debug().Str("provider", hwf.Provider).Str("url", SmHotWordsUrl).Msgf("SmHotWordFind")
// fetch data
response, body, err := gorequest.New().
TLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
Set("Content-Type", "application/json").
Timeout(HotWordHttpTimeout * time.Second).
Get(SmHotWordsUrl).End()
if nil != err || http.StatusOK != response.StatusCode {
return nil, errors.New("fetch sm hotspot failed")
}
hotwords := gjson.ParseBytes([]byte(body))
// format json
lists := map[string]int64{}
for _, hotword := range hotwords.Array() {
keyword := hotword.Get("title").String()
weight := hotword.Get("hot_flag").Int()
suggestUrl := hwf.GetSuggestUrl(keyword, from, suggestUrl)
if lists[keyword] == 0 {
lists[keyword] = weight
hwr := &HotWordResult{
Keyword: keyword,
Weight: int(weight),
SuggestUrl: suggestUrl,
}
hwrs = append(hwrs, hwr)
}
}
return hwrs, nil
}