Last active
December 12, 2015 02:49
-
-
Save coldfire-x/4702191 to your computer and use it in GitHub Desktop.
get my stock price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"net/http" | |
"encoding/json" | |
"io/ioutil" | |
) | |
func getPrices(codes []string) { | |
url := "http://cj.gw.com.cn/stockHq.php" | |
timestamp := time.Now().UnixNano() / 10e5 | |
url = fmt.Sprintf("%s?&_=%d&code=", url, timestamp) | |
for _, stock := range codes { | |
url += stock + ";" | |
} | |
//fmt.Println(url) | |
respose, err := http.Get(url) | |
defer respose.Body.Close() | |
if err != nil { | |
fmt.Println("Something Wrong happened!") | |
} | |
body, _ := ioutil.ReadAll(respose.Body) | |
//fmt.Printf("%v", string(body)) | |
var m []interface{} | |
json.Unmarshal(body, &m) | |
// fmt.Println(m) | |
for _, v := range m { | |
k := v.(map[string]interface{}) | |
fmt.Printf("%s%8s%8s\n", k["name"], k["lp"], k["zf"]) | |
} | |
} | |
func main() { | |
stockCodes := []string{"SZ002151", "SH600118"} | |
//fmt.Println(stockCodes) | |
getPrices(stockCodes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment