예제 #1
0
/*
使用淘宝代理查询ip
*/
func GetIpInfo(ip string) string {

	//	println("return 2")
	//	return "2"
	if ip == "127.0.0.1" {
		return "1"
	}
	response, err := http.Get("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip)

	if err != nil {
		fmt.Println("err:", err)
		return "9"
	}

	defer response.Body.Close()

	if err != nil || response.StatusCode != http.StatusOK {
		return "2"
	}
	//	defer response.Body.Close()

	body, _ := ioutil.ReadAll(response.Body)
	s := string(body)
	gojson.Json(s).Get("data").Get("country").Tostring() // 中国
	gojson.Json(s).Get("data").Get("area").Tostring()    // 华南
	gojson.Json(s).Get("data").Get("region").Tostring()  // 广东省
	gojson.Json(s).Get("data").Get("city").Tostring()    // 广东省

	return "3"
}
예제 #2
0
func jsonFormat(data []byte) {
	//第三方json库
	jsonMap := gojson.Json(string(data))
	fmt.Println(jsonMap)

	//golang自带json库
	var dat map[string]interface{}
	err := json.Unmarshal(data, &dat)
	if err != nil {
		panic(err)
	}
	fmt.Println(dat)
	format, _ := json.MarshalIndent(dat, "", "  ")
	fmt.Println(string(format))
}
예제 #3
0
func TestIpCity(t *testing.T) {

	ip := "113.106.106.98"
	response, _ := http.Get("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip)
	defer response.Body.Close()
	body, _ := ioutil.ReadAll(response.Body)
	println(response.Status)
	fmt.Println(string(body))

	s := string(body)
	c1 := gojson.Json(s).Get("data").Get("area")
	ipMap[ip] = c1.Tostring()
	println(ipMap[ip])
	if ipMap[ip] == nil {
		println("errr")
	}

	println(c1.Tostring())
}
예제 #4
0
파일: goreview.go 프로젝트: wadee/go_proj
func main() {

	//读取文件
	f, err := os.Open("/tmp/zehua.out")
	if err != nil {
		panic("file open failed!")
	}
	defer f.Close()

	b := bufio.NewReader(f)
	line, err := b.ReadString('\n')

	for ; err == nil; line, err = b.ReadString('\n') {
		slice := strings.Split(line, "\t")
		mid := slice[0]
		uid := slice[1]
		content := slice[2]
		reg, err := regexp.Compile(`http:\/\/t.cn\/[a-zA-Z0-9]+`)

		var short_url string
		if err == nil {
			short_url = reg.FindString(content)

		}
		// 获取短链的对象信息
		// var obj_info OBJINFO
		// obj_info := make(map[string][]map[string][]map[string]string)

		post_data := map[string]string{"source": "3439264077", "url_short": short_url}

		ret_byte := Request("http://i.api.weibo.com/2/short_url/info.json", "GET", post_data)

		json_data := gojson.Json(string(ret_byte))

		var object_id string
		var score string
		var timestamp string
		if ann := json_data.Get("urls").Getindex(1).Get("annotations"); ann != nil {
			if ann_1 := ann.Getindex(1); ann_1 != nil {
				object_id = gojson.Json(string(ret_byte)).Get("urls").Getindex(1).Get("annotations").Getindex(1).Get("object_id").Tostring()
				// fmt.Println(gojson.Json(string(ret_byte)).Get("urls").Getindex(1).Get("annotations").Getindex(1).Get("dynamic").Get("score"), score)

				// if dynamic := temp.Get("dynamic"); dynamic != nil {
				// 	fmt.Println(temp)
				// 	score = dynamic.Get("score").Tostring()
				// }

			}

		}

		r, _ := regexp.Compile(`★+`)

		substr := r.FindString(content)

		score = strconv.Itoa(len(substr) / 3 * 2)

		mid_post_data := map[string]string{"source": "2346240190", "ids": mid}

		mid_ret := Request("http://i.api.weibo.com/2/statuses/show_batch.json", "GET", mid_post_data)

		json_data = gojson.Json(string(mid_ret))

		if status := json_data.Get("statuses").Getindex(1); status != nil {
			timestamp = status.Get("created_at").Tostring()
			t, err := time.Parse(time.RubyDate, timestamp)
			if err == nil {
				timestamp = strconv.FormatInt(t.Unix(), 10)
			}
		}

		review := map[string]string{"object_id": object_id, "score": score, "user_id": uid, "mid": mid, "last_modified": timestamp}
		json_review, err := json.Marshal(review)

		spr := "http://weibo.com/u/" + uid
		data := map[string]string{"source": "2346240190", "object_id": object_id, "user_id": uid, "review": string(json_review), "spr": spr}

		review_add := Request("http://i.api.weibo.com/2/darwin/review/add.json", "POST", data)
		fmt.Println(string(review_add))

		// fmt.Println(json_data.Get("statuses").Getindex(1).Get("created_at"))
		// json.Unmarshal(ret_byte, &obj_info)

		// var oid string
		// if value, ok := obj_info["urls"][0]["annotations"].([]interface{}); ok {
		// 	for _, item := range value {
		// 		if val, test := item.(map[string]interface{}); test {
		// 			if object_id, is_string := val["object_id"].(string); is_string {
		// 				oid = object_id

		// 			}
		// 			if dynaimc,
		// 		}
		// 	}
		// }
		time.Sleep(time.Second)
	}

	if err == io.EOF {
		fmt.Println(line)
	} else {
		fmt.Errorf("read err")
	}

	// ret := Request("http://www.baidu.com", "POST", nil)

}