|
|
@ -8,6 +8,8 @@ import ( |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
"io/ioutil" |
|
|
|
|
|
|
|
"encoding/json" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type SinaStock struct { |
|
|
|
type SinaStock struct { |
|
|
@ -30,6 +32,7 @@ func (s *SinaStock) Url() string { |
|
|
|
|
|
|
|
|
|
|
|
func (s *SinaStock) OnRequest(r *colly.Request) { |
|
|
|
func (s *SinaStock) OnRequest(r *colly.Request) { |
|
|
|
//fmt.Println(r.URL)
|
|
|
|
//fmt.Println(r.URL)
|
|
|
|
|
|
|
|
r.Headers.Set("Referer", "http://finance.sina.com.cn/") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *SinaStock) Split(r rune) bool { |
|
|
|
func (s *SinaStock) Split(r rune) bool { |
|
|
@ -66,7 +69,11 @@ func (s *SinaStock) DecodeMarket(str string) { |
|
|
|
a.Date = marketList[30] |
|
|
|
a.Date = marketList[30] |
|
|
|
a.Time = marketList[31] |
|
|
|
a.Time = marketList[31] |
|
|
|
a.Flag = marketList[32] |
|
|
|
a.Flag = marketList[32] |
|
|
|
|
|
|
|
if _, ok := stock.G_STOCK_MANAGER.StockList[symbol]; ok { |
|
|
|
stock.G_STOCK_MANAGER.StockList[symbol].Market = a |
|
|
|
stock.G_STOCK_MANAGER.StockList[symbol].Market = a |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
fmt.Println("not found", symbol) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *SinaStock) OnResponse(res *colly.Response) { |
|
|
|
func (s *SinaStock) OnResponse(res *colly.Response) { |
|
|
@ -76,7 +83,17 @@ func (s *SinaStock) OnResponse(res *colly.Response) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *SinaStock) Start() { |
|
|
|
//contains
|
|
|
|
|
|
|
|
func contains(s []string, e string) bool { |
|
|
|
|
|
|
|
for _, a := range s { |
|
|
|
|
|
|
|
if a == e { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *SinaStock) Start(fn string) { |
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
select { |
|
|
@ -84,6 +101,10 @@ func (s *SinaStock) Start() { |
|
|
|
ipos := 1 |
|
|
|
ipos := 1 |
|
|
|
params := make([]string, 0) |
|
|
|
params := make([]string, 0) |
|
|
|
param := "" |
|
|
|
param := "" |
|
|
|
|
|
|
|
//fmt.Println(stock.G_STOCK_MANAGER.IndexList)
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile(fn) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
//fmt.Println(err)
|
|
|
|
for k, _ := range stock.G_STOCK_MANAGER.StockList { |
|
|
|
for k, _ := range stock.G_STOCK_MANAGER.StockList { |
|
|
|
if ipos%800 == 0 { |
|
|
|
if ipos%800 == 0 { |
|
|
|
params = append(params, param) |
|
|
|
params = append(params, param) |
|
|
@ -93,6 +114,12 @@ func (s *SinaStock) Start() { |
|
|
|
param += "," |
|
|
|
param += "," |
|
|
|
ipos++ |
|
|
|
ipos++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
var stocks []string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(data), &stocks) |
|
|
|
|
|
|
|
param = strings.Join(stocks, ",") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//fmt.Println(param)
|
|
|
|
params = append(params, param) |
|
|
|
params = append(params, param) |
|
|
|
for _, str := range params { |
|
|
|
for _, str := range params { |
|
|
|
url := s.Url() + str |
|
|
|
url := s.Url() + str |
|
|
|