-
Notifications
You must be signed in to change notification settings - Fork 0
/
bodys.go
70 lines (66 loc) · 1.33 KB
/
bodys.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
69
70
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"os"
"time"
)
func ParseSiteSkc(filename string) map[string][]string {
csvFile, _ := os.Open(filename)
reader := csv.NewReader(bufio.NewReader(csvFile))
ret := make(map[string][]string, 4)
for {
line, error := reader.Read()
if error == io.EOF {
break
} else if error != nil {
log.Fatal(error)
}
temp := ret[line[0]]
temp = append(temp, line[1])
ret[line[0]] = temp
}
return ret
}
func ContructBody(src map[string][]string) []byte {
size := 200
sites := [4]string{"shein", "romwe"}
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
rnd := r.Intn(len(sites))
site := sites[rnd]
skcs := src[site]
// fmt.Println(len(skcs))
slice := len(skcs) - size
if slice > 0 {
skcs, src[site] = skcs[slice:], skcs[:slice]
} else {
skcs = []string{}
}
ret := make(map[string]interface{})
ret["site"] = site
ret["skc_list"] = skcs
jsonString, _ := json.Marshal(ret)
return jsonString
}
func _main() {
csv := ParseSiteSkc("c:/Users/wenfe/site_skc.csv")
fmt.Println(len(csv["shein"]))
fmt.Println(len(csv["romwe"]))
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
ContructBody(csv)
}