-
Notifications
You must be signed in to change notification settings - Fork 0
/
yanxuan.go
59 lines (49 loc) · 1.02 KB
/
yanxuan.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
package main
import (
"compress/gzip"
"context"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"regexp"
)
//通过平台API查询库存
func checkYanXuanStockByAPI(ctx context.Context, URL string, ch chan bool) {
defer func() {
luNum--
ch <- true
}()
luNum++
var (
err error
req *http.Request
resp *http.Response
)
if req, err = http.NewRequest(`GET`, URL, nil); err != nil {
log.Println(err)
return
}
if resp, err = http.DefaultClient.Do(req); err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
var reader io.Reader
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, _ = gzip.NewReader(resp.Body)
default:
reader = resp.Body
}
returnStr, _ := ioutil.ReadAll(reader)
flysnowRegexp := regexp.MustCompile(`"soldOut":(true|false).+"status":(\d)`)
params := flysnowRegexp.FindStringSubmatch(string(returnStr))
if len(params) > 2 && params[1] == "false" && params[2] != "0" {
fmt.Println(URL, "有货")
noticeByBark(URL)
} else {
fmt.Println(URL, "无货")
}
}