-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcbnew.go
More file actions
156 lines (135 loc) · 3.85 KB
/
cbnew.go
File metadata and controls
156 lines (135 loc) · 3.85 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
)
var (
schedule bool
sckey string
barkkey string
hour int
minute int
)
func main() {
if schedule {
fmt.Printf("运行中...每天%v时%v分推送\r\n", hour, minute)
startScheduler(hour, minute, time.Hour*24)
} else {
fmt.Println("推送中...")
doJob()
fmt.Println("推送完成...")
}
}
func init() {
flag.StringVar(&sckey, "sckey", "", "请设置SCKEY")
flag.StringVar(&barkkey, "barkkey", "", "请设置BarkKey")
flag.BoolVar(&schedule, "s", false, "请设置是否调度")
flag.IntVar(&hour, "h", 9, "请设置开始小时")
flag.IntVar(&minute, "m", 0, "请设置开始分钟")
flag.Parse()
if sckey == "" && barkkey == "" {
panic("请至少设置sckey或barkkey其中一种")
}
}
func pushInfo(title string, text string) {
fmt.Println(title)
fmt.Println(text)
// 使用Server酱推送
if sckey != "" {
resp, _ := http.Get("https://sc.ftqq.com/" + sckey + ".send?text=" + title + "&desp=" + text)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("Server酱推送结果" + string(body))
}
// 使用Bark推送
if barkkey != "" {
resp, _ := http.Get("https://api.day.app/" + barkkey + "/" + title + "/" + text)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("BARK推送结果" + string(body))
}
}
func doJob() {
applyList, listList := getTodayCbInfo()
for _, apply := range applyList {
pushInfo("今日可打新债", apply)
}
for _, list := range listList {
pushInfo("今日上市债券", list)
}
if len(applyList) == 0 {
pushInfo("今日无可打新债", "")
}
if len(listList) == 0 {
pushInfo("今日无上市债券", "")
}
}
func startScheduler(hour int, minute int, duration time.Duration) {
now := time.Now()
first := time.Date(now.Year(), now.Month(), now.Day(), hour, minute, 00, 0, now.Location())
if first.Before(now) {
first = first.Add(time.Hour * 24)
}
starter := time.NewTicker(first.Sub(now))
<-starter.C
starter.Stop()
scheduler := time.NewTicker(duration)
for {
doJob()
<-scheduler.C
}
defer scheduler.Stop()
}
func getTodayCbInfo() (applyList []string, listList []string) {
uri := "https://www.jisilu.cn/data/cbnew/pre_list/"
client := &http.Client{}
req, _ := http.NewRequest("POST", uri, strings.NewReader("rp=22"))
req.Header.Set("Origin", "https://www.jisilu.cn")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36")
req.Header.Set("X-Requested-With", "XMLHttpRequest")
req.Header.Set("Referer", "https://www.jisilu.cn/data/cbnew/")
req.Header.Set("Accept", "application/json, text/javascript, */*; q=0.01")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("Accept-Language", "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7")
resp, err := client.Do(req)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
var info Info
json.Unmarshal(body, &info)
todayStr := time.Now().Format("2006-01-02")
for _, row := range info.Rows {
if row.Cell.ApplyDate == todayStr {
applyList = append(applyList, conv(row.Cell))
}
if row.Cell.ListDate == todayStr {
listList = append(listList, conv(row.Cell))
}
}
return applyList, listList
}
func conv(cell Cell) string {
return "名称:" + cell.Name + ",申购日期:" + cell.ApplyDate + ",上市日期:" + cell.ApplyDate
}
type Info struct {
Page int `json:"page"`
Rows []Row `json:"rows"`
}
type Row struct {
Id string `json:"id"`
Cell Cell `json:"cell"`
}
type Cell struct {
Name string `json:"bond_nm"`
ApplyDate string `json:"apply_date"`
ListDate string `json:"list_date"`
Advise string `json:"jsl_advise_text"`
BondId string `json:"bond_id"`
DrawRate string `json:"lucky_draw_rt"`
Rating string `json:"rating_cd"`
}