|
|
|
@ -8,6 +8,8 @@ import ( |
|
|
|
|
"reflect" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"encoding/json" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type SinaStock struct { |
|
|
|
@ -29,7 +31,8 @@ func (s *SinaStock) Url() string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
@ -66,7 +69,11 @@ func (s *SinaStock) DecodeMarket(str string) { |
|
|
|
|
a.Date = marketList[30] |
|
|
|
|
a.Time = marketList[31] |
|
|
|
|
a.Flag = marketList[32] |
|
|
|
|
if _, ok := stock.G_STOCK_MANAGER.StockList[symbol]; ok { |
|
|
|
|
stock.G_STOCK_MANAGER.StockList[symbol].Market = a |
|
|
|
|
}else{ |
|
|
|
|
fmt.Println("not found", symbol) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
@ -84,6 +101,10 @@ func (s *SinaStock) Start() { |
|
|
|
|
ipos := 1 |
|
|
|
|
params := make([]string, 0) |
|
|
|
|
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 { |
|
|
|
|
if ipos%800 == 0 { |
|
|
|
|
params = append(params, param) |
|
|
|
@ -93,6 +114,12 @@ func (s *SinaStock) Start() { |
|
|
|
|
param += "," |
|
|
|
|
ipos++ |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
var stocks []string |
|
|
|
|
err = json.Unmarshal([]byte(data), &stocks) |
|
|
|
|
param = strings.Join(stocks, ",") |
|
|
|
|
} |
|
|
|
|
//fmt.Println(param)
|
|
|
|
|
params = append(params, param) |
|
|
|
|
for _, str := range params { |
|
|
|
|
url := s.Url() + str |
|
|
|
|