コード例 #1
0
ファイル: string.go プロジェクト: enderlu/vfp
/*
1 Converts single-byte characters in cExpression to double-byte characters.

  Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).

2 Converts double-byte characters in cExpression to single-byte characters.

  Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).

3 Converts double-byte Katakana characters in cExpression to double-byte Hiragana characters.

 Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).

4 Converts double-byte Hiragana characters in cExpression to double-byte Katakana characters.

  Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).

5 Converts double-byte characters to UNICODE (wide characters).

6 Converts UNICODE (wide characters) to double-byte characters.

7 Converts cExpression to locale-specific lowercase.

  Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).

8 Converts cExpression to locale-specific uppercase.

  Supported for Locale ID only (specified with the nRegionalIdentifier or nRegionalIDType parameters).





13 Converts single-byte characters in cExpression to encoded base64 binary.

14 Converts base64 encoded data in cExpression to original unencoded data.

15 Converts single-byte characters in cExpression to encoded hexBinary.

16 Converts single-byte characters in cExpression to decoded hexBinary

*/
func Strconv(zstr string, zconvertType int) string {

	zcharset := ""

	switch zconvertType {
	case 9: //9 Converts double-byte characters in cExpression to UTF-8
		zcharset = getCurrentCP()
		dec := mahonia.NewDecoder(zcharset)
		return dec.ConvertString(zstr)
	case 10: //10 Converts Unicode characters in cExpression to UTF-8
		zcharset = "utf16"
		dec := mahonia.NewDecoder(zcharset)
		return dec.ConvertString(zstr)

	case 11: //11 Converts UTF-8 characters in cExpression to double-byte characters.
		zcharset = getCurrentCP()
		enc := mahonia.NewEncoder(zcharset)
		return enc.ConvertString(zstr)
	case 12: //12 Converts UTF-8 characters in cExpression to UNICODE characters.
		zcharset = "utf16"
		enc := mahonia.NewEncoder(zcharset)
		return enc.ConvertString(zstr)

	}
	return zstr
}
コード例 #2
0
ファイル: stock.go プロジェクト: ebookbug/BigStocks
func getStockInfo(code string) (s *Stock, err error) {
	var qturl = "http://qt.gtimg.cn/q=s_"
	resp, _ := http.Get(qturl + code)
	ctn, _ := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()

	enc := mahonia.NewDecoder("gbk")
	gbct := enc.ConvertString(string(ctn))
	fmt.Println(gbct)
	if strings.Contains(gbct, "none_match") {
		return s, nil
	}

	inx1 := strings.Index(gbct, "\"")
	inx2 := strings.LastIndex(gbct, "\"")

	fmt.Println(gbct[inx1+1 : inx2])

	ctns := strings.Split(gbct[inx1+1:inx2], "~")
	s = &Stock{}
	s.Name = ctns[1]
	s.Code = code[2:]
	s.Area = code[:2]

	return
}
コード例 #3
0
ファイル: gp.go プロジェクト: dengweiwen/WeiXin
func GuPiao(no string) string {
	client := &http.Client{}
	url := ""
	if strings.HasPrefix(no, "60") || strings.HasPrefix(no, "51") {
		url = "http://hq.sinajs.cn/list=sh" + no
	} else if strings.HasPrefix(no, "00") || strings.HasPrefix(no, "30") {
		url = "http://hq.sinajs.cn/list=sz" + no
	}

	reqest, err := http.NewRequest("GET", url, nil)

	if err != nil {
		return "代碼錯誤"
	}
	reqest.Header.Add("Accept-Language", "zh-CN,zh;q=0.8")
	reqest.Header.Add("Content-Type", "text/html; charset=utf-8")
	resp, err := client.Do(reqest)
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "代碼錯誤"
	}
	dec := mahonia.NewDecoder("GBK")
	s := dec.ConvertString(string(data))
	s = s[strings.Index(s, "\"")+1 : strings.LastIndex(s, "\"")]
	s = GuPiaoFormat(s)
	fmt.Println(s)
	return s
}
コード例 #4
0
ファイル: code.go プロジェクト: ebookbug/BigStocks
func getStockInfoFromSina(s *Stock) {
	var qturl = "http://hq.sinajs.cn/list="
	resp, _ := http.Get(qturl + s.Area + s.Code)
	ctn, _ := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()

	enc := mahonia.NewDecoder("gbk")
	gbct := enc.ConvertString(string(ctn))

	if strings.Contains(gbct, "none_match") {
		return
	}

	fmt.Println(s.Area, s.Code, ":", gbct)
	inx1 := strings.Index(gbct, "\"")
	inx2 := strings.LastIndex(gbct, "\"")

	fmt.Println(gbct[inx1+1 : inx2])

	ctns := strings.Split(gbct[inx1+1:inx2], ",")
	s.Name = ctns[0]

	fmt.Println(ctns)

}
コード例 #5
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func enableInterface() (name string, err error) {
	for win := range system {
		cmd := exec.Command("cmd.exe", "/c", `netsh interface show interface name=`+system[win])
		out, _ := cmd.StdoutPipe()

		err = cmd.Start()
		if err != nil {
			fmt.Println("enableInteface", err)
			return "", err
		}
		ma := mahonia.NewDecoder("gbk")
		buf := ma.NewReader(out)
		data := make([]byte, 1<<16)
		n, _ := buf.Read(data)
		if strings.Contains(string(data[:n]), "管理状态: 已禁用") {
			name = system[win]
			fmt.Printf("网卡 [%s] 禁用状态,正在启用网卡,请稍等.\n", name)
			err = enabled(true, name)
		}

		cmd.Wait()
	}

	return name, err
}
コード例 #6
0
ファイル: utf8tobig5.go プロジェクト: enderlu/vfp
func DisplayUrl(zurl string) {
	println("loading ...", zurl)
	r, err1 := http.Get(zurl)

	checkError(err1)
	println("complete !", r.StatusCode)
	decoder := mahonia.NewDecoder("gb18030") //gb18030可以适用于gb2312
	//decoder := mahonia.NewDecoder("utf8")
	//decoder := mahonia.NewDecoder("big5")
	bs := make([]byte, 5056)

	var buf []byte
	defer r.Body.Close()

	n, err1 := r.Body.Read(bs)
	zi := 0
	for n > 0 {
		if n > 0 {
			zi++
			buf = append(buf, bs[:n]...)
		}
		n, err1 = r.Body.Read(bs)
	}
	println("read complete !", "times:", zi)

	_, line, _ := decoder.Translate(buf, true)
	println(n, string(line))
}
コード例 #7
0
ファイル: trader.go プロジェクト: imbugs/gotrade
func (account *Account) base64decode(str string) string {
	data, _ := base64.StdEncoding.DecodeString(str)
	str = fmt.Sprintf("%s", data)
	enc := mahonia.NewDecoder("gbk")
	gbk := enc.ConvertString(str)
	gbk = strings.Replace(gbk, "\n", "", -1)
	return gbk
}
コード例 #8
0
ファイル: main.go プロジェクト: youmuyou/cnki-downloader
//
// input a reader(gbk), output a reader(utf-8)
//
func gbk2utf8(charset string, r io.Reader) (io.Reader, error) {
	if charset != "gb2312" {
		return nil, fmt.Errorf("Unsupported charset")
	}

	decoder := mahonia.NewDecoder("gbk")
	reader := decoder.NewReader(r)
	return reader, nil
}
コード例 #9
0
ファイル: page.go プロジェクト: karlek/nyfiken
// Download the page with or without user specified headers.
func (p *Page) download() (doc *html.Node, err error) {

	// Construct the request.
	req, err := http.NewRequest("GET", p.ReqUrl.String(), nil)
	if err != nil {
		return nil, errutil.Err(err)
	}

	// If special headers were specified, add them to the request.
	if p.Settings.Header != nil {
		for key, val := range p.Settings.Header {
			req.Header.Add(key, val)
		}
	}

	// Do request and read response.
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		if serr, ok := err.(*url.Error); ok {
			if serr.Err == io.EOF {
				return nil, errutil.NewNoPosf("Update was empty: %s", p.ReqUrl)
			}
		}
		return nil, errutil.Err(err)
	}
	defer resp.Body.Close()

	// If response contained a client or server error, fail with that error.
	if resp.StatusCode >= 400 {
		return nil, errutil.Newf("%s: (%d) - %s", p.ReqUrl.String(), resp.StatusCode, resp.Status)
	}

	// Read the response body to []byte.
	buf, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errutil.Err(err)
	}

	// Fix charset problems with servers that doesn't use utf-8
	charset := "utf-8"
	content := string(buf)

	types := strings.Split(resp.Header.Get("Content-Type"), ` `)
	for _, typ := range types {
		if strings.Contains(typ, "charset") {
			keyval := strings.Split(typ, `=`)
			if len(keyval) == 2 {
				charset = keyval[1]
			}
		}
	}
	if charset != "utf-8" {
		content = mahonia.NewDecoder(charset).ConvertString(content)
	}
	// Parse response into html.Node.
	return html.Parse(strings.NewReader(content))
}
コード例 #10
0
ファイル: charset.go プロジェクト: qiangmzsx/golang
func main() {
	enc := mahonia.NewEncoder("gbk")
	gbk := enc.ConvertString("失落伐克欧洲杯")
	fmt.Println(gbk)

	//enc = mahonia.NewEncoder("utf8")
	dec := mahonia.NewDecoder("gbk")
	utf8 := dec.ConvertString(gbk)
	fmt.Println(utf8)
}
コード例 #11
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func getResult(out io.ReadCloser) (result string, err error) {
	n := 0
	buf := make([]byte, 1<<16)
	if runtime.GOOS == "windows" {
		gbk := mahonia.NewDecoder("gbk")
		reader := gbk.NewReader(out)
		n, err = reader.Read(buf)
	} else {
		n, err = out.Read(buf)
	}

	return string(buf[:n]), err
}
コード例 #12
0
ファイル: dbftable.go プロジェクト: ArmandGrillet/go-dbf
func (dt *DbfTable) getNormalizedFieldName(name string) (s string) {
	e := mahonia.NewEncoder(dt.fileEncoding)
	b := []byte(e.ConvertString(name))

	if len(b) > 10 {
		b = b[0:10]
	}

	d := mahonia.NewDecoder(dt.fileEncoding)
	s = d.ConvertString(string(b))

	return
}
コード例 #13
0
ファイル: qqwry.go プロジェクト: llych/qqwry
func (this *QQwry) Find(ip string) {
	if this.filepath == "" {
		return
	}

	file, err := os.OpenFile(this.filepath, os.O_RDONLY, 0400)
	defer file.Close()
	if err != nil {
		return
	}
	this.file = file

	this.Ip = ip
	offset := this.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
	// log.Println("loc offset:", offset)
	if offset <= 0 {
		return
	}

	var country []byte
	var area []byte

	mode := this.readMode(offset + 4)
	// log.Println("mode", mode)
	if mode == REDIRECT_MODE_1 {
		countryOffset := this.readUInt24()
		mode = this.readMode(countryOffset)
		// log.Println("1 - mode", mode)
		if mode == REDIRECT_MODE_2 {
			c := this.readUInt24()
			country = this.readString(c)
			countryOffset += 4
		} else {
			country = this.readString(countryOffset)
			countryOffset += uint32(len(country) + 1)
		}
		area = this.readArea(countryOffset)
	} else if mode == REDIRECT_MODE_2 {
		countryOffset := this.readUInt24()
		country = this.readString(countryOffset)
		area = this.readArea(offset + 8)
	} else {
		country = this.readString(offset + 4)
		area = this.readArea(offset + uint32(5+len(country)))
	}

	enc := mahonia.NewDecoder("gbk")
	this.Country = enc.ConvertString(string(country))
	this.City = enc.ConvertString(string(area))

}
コード例 #14
0
ファイル: gocal.go プロジェクト: valkum/gocal
func request(method string, url string, cl *http.Client, params url.Values) (string, http.Header, http.Request) {

	var err error
	var req *http.Request
	// ...
	//req.Header.Add("If-None-Match", `W/"wyzzy"`)

	if method == "post" {
		req, err = http.NewRequest("POST", url, strings.NewReader(params.Encode()))
		req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	} else {
		req, err = http.NewRequest("GET", url+"?"+params.Encode(), nil)
	}
	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36")
	req.Header.Set("Origin", "www.campus.rwth-aachen.de")
	req.Header.Set("Referer", "https://www.campus.rwth-aachen.de/office/views/campus/redirect.asp")
	req.Header.Set("Accept-Language", "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4")
	req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
	// for _, c := range cookieJar.cookies {
	//     req.AddCookie(c)
	// }

	var resp *http.Response
	resp, err = cl.Do(req)
	// if cl.Jar != nil {
	if rc := readSetCookies(resp.Header); len(rc) > 0 {
		cookieJar.SetCookies(req.URL, rc)
	}
	// }
	// spew.Dump(resp.Header)
	defer resp.Body.Close()

	if err != nil {
		fmt.Printf("Error from client.Do: %s\n", err)
	}
	var bodyString string
	//var err2 error
	if resp.StatusCode == 200 { // OK
		bodyBytes, _ := ioutil.ReadAll(resp.Body)
		if utf8.Valid(bodyBytes) {
			bodyString = string(bodyBytes)
		} else {
			enc := mahonia.NewDecoder("latin-1")
			bodyString = enc.ConvertString(string(bodyBytes))
		}
	}

	return bodyString, resp.Header, *req

}
コード例 #15
0
ファイル: cmd.go プロジェクト: CodyGuo/Go-Cody
func (m *iManIP) GetCmdResult(out io.ReadCloser) (result string, err error) {
	if m.Cmd == nil {
		return "", errors.New("The cmd not create!")
	}

	gbk := mahonia.NewDecoder("gbk")
	reader := gbk.NewReader(out)
	buf := make([]byte, 1<<16)
	n, err := reader.Read(buf)

	result = string(buf[:n])

	return
}
コード例 #16
0
ファイル: charset_reader.go プロジェクト: noscripter/rss
func charsetReader(charset string, input io.Reader) (io.Reader, error) {
	switch {
	case isCharsetUTF8(charset):
		return input, nil
	case isCharsetISO88591(charset):
		return newCharsetISO88591(input), nil
	default:
		if decoder := mahonia.NewDecoder(charset); decoder != nil {
			return decoder.NewReader(input), nil
		}
	}

	return nil, errors.New("CharsetReader: unexpected charset: " + charset)
}
コード例 #17
0
ファイル: utf8tobig5.go プロジェクト: enderlu/vfp
func DisplayFile(zfile string) {
	f, err := os.Open(zfile)
	checkError(err)
	defer f.Close()
	decoder := mahonia.NewDecoder("gb18030")
	//decoder := mahonia.NewDecoder("utf8")
	//decoder := mahonia.NewDecoder("big5")
	r := bufio.NewReader(decoder.NewReader(f))
	line, _, err := r.ReadLine()
	for err == nil {
		checkError(err)
		println(string(line))
		line, _, err = r.ReadLine()
	}
}
コード例 #18
0
ファイル: dialvpn.go プロジェクト: mskyspet/gotools
func (this *WindowsDialer) runCommand(command string, args ...string) string {
	cmd := exec.Command(command, args...)
	out := bytes.Buffer{}
	cmd.Stdout = &out
	err := cmd.Run()

	cmdOutput := out.String()
	enc := mahonia.NewDecoder("gbk")
	cmdOutput = enc.ConvertString(cmdOutput)

	if err != nil {
		log.Panic(cmdOutput)
	}
	return cmdOutput
}
コード例 #19
0
func handlePath(root string) {
	ws := NewWordSetting()
	decoder := mahonia.NewDecoder(Encoding)
	files := getFilePath(root)
	for _, f := range files {
		fullfilepath := filepath.Join(f.folder, f.filename)
		log.Printf("正在处理文件: %s", fullfilepath)
		content := util.ReadFile(fullfilepath)
		//if ret, ok := decoder.ConvertStringOK(content); ok {
		//    content = ret
		//}
		content = decoder.ConvertString(content)
		pairTerm := getWords(content, ws)
		writeOutput(f, pairTerm, ws.outputFreq)
	}
}
コード例 #20
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func printValue(pdu gosnmp.SnmpPDU) error {
	fmt.Printf("%s = ", pdu.Name)
	dec := mahonia.NewDecoder("gbk")
	switch pdu.Type {
	case gosnmp.OctetString:
		b := pdu.Value.([]byte)
		_, date, _ := dec.Translate(b, true)
		fmt.Printf("STRING: %s\n", string(date))
	case gosnmp.IPAddress:
		b := pdu.Value.(string)
		fmt.Printf("IpAddress: %s\n", string(b))
	default:
		fmt.Printf("TYPE %d: %d\n", pdu.Type, gosnmp.ToBigInt(pdu.Value))
	}
	return nil
}
コード例 #21
0
func main() {
	// 用户 Cookie
	var cookie string = "oMVX_2132_saltkey=BQ1dWrGn;oMVX_2132_auth=95f6c%2BOg2r7RFCtaANsi%2FDKG8KHdIZeQ1PEfL79b8NVnVBZiyo%2F8RaRFCDqvO8qC2o34ND%2FpV1gDVYiNNOujs%2FZy048;"
	// regexp.MustCompile 返回一个值, 可用于常量定义
	// regexp.Compile 返回两个值, 第二个值表示错误
	hash_pattern := regexp.MustCompile(`formhash=(.+)">.+?</a>`)
	resp_pattern := regexp.MustCompile(`<div class="c">\s*?(.+?)<a href="`)

	client := &http.Client{}

	request, _ := http.NewRequest("GET", "http://bbs.fishc.com/plugin.php?id=dsu_paulsign:sign", nil)

	request.Header.Set(
		"Cookie",
		cookie)

	res, _ := client.Do(request)

	body_, _ := ioutil.ReadAll(res.Body)
	// fmt.Println(string(body_))

	defer res.Body.Close()

	formhash := hash_pattern.FindStringSubmatch(string(body_))[1]
	// fmt.Println(formhash)

	req, _ := http.NewRequest(
		"POST",
		"http://bbs.fishc.com/plugin.php?id=dsu_paulsign:sign&operation=qiandao&inajax=1",
		strings.NewReader("qdxq=kx&qdmode=2&todaysay=&fastreply=1&formhash="+formhash))

	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Cookie", cookie)

	response, _ := client.Do(req)

	body, _ := ioutil.ReadAll(response.Body)

	defer response.Body.Close()

	output := mahonia.NewDecoder("GBK").ConvertString(string(body))

	result := resp_pattern.FindStringSubmatch(output)[1]

	fmt.Println(result)
}
コード例 #22
0
ファイル: qqwry.go プロジェクト: zhangf911/qqwry
func (this *QQwry) Find(ip string) (res resultQQwry) {

	res = resultQQwry{}

	res.Ip = ip
	if strings.Count(ip, ".") != 3 {
		return res
	}
	offset := this.searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
	if offset <= 0 {
		return
	}

	var country []byte
	var area []byte

	mode := this.readMode(offset + 4)
	if mode == REDIRECT_MODE_1 {
		countryOffset := this.readUInt24()
		mode = this.readMode(countryOffset)
		if mode == REDIRECT_MODE_2 {
			c := this.readUInt24()
			country = this.readString(c)
			countryOffset += 4
		} else {
			country = this.readString(countryOffset)
			countryOffset += uint32(len(country) + 1)
		}
		area = this.readArea(countryOffset)
	} else if mode == REDIRECT_MODE_2 {
		countryOffset := this.readUInt24()
		country = this.readString(countryOffset)
		area = this.readArea(offset + 8)
	} else {
		country = this.readString(offset + 4)
		area = this.readArea(offset + uint32(5+len(country)))
	}

	enc := mahonia.NewDecoder("gbk")
	res.Country = enc.ConvertString(string(country))
	res.Area = enc.ConvertString(string(area))

	return
}
コード例 #23
0
ファイル: spilder.go プロジェクト: wenxiaoyu/traffic
func Detail(url string) *D {
	detail := new(D)

	resp, err := http.Get(url)
	if err == nil {
		body, err1 := ioutil.ReadAll(resp.Body)
		if err1 != nil {
			return nil
		}
		html := string(body)
		enc := mahonia.NewDecoder("UTF-8")
		encHtml := enc.ConvertString(html)
		doc, _ := gokogiri.ParseHtml([]byte(encHtml))

		img, _ := doc.Search("//section[@class='show_box']/div[2]/img")
		intro, _ := doc.Search("//div[@class='daoyu']")
		content, _ := doc.Search("//section[@class='show_box']/article/p")

		if len(img) > 0 {
			detail.ImgUrl = img[0].Attr("src")
		}
		if len(intro) > 0 {
			detail.Intro = intro[0].Content()
		}

		for _, v := range content {

			if strings.Contains(v.Content(), "浏览大图") {
				continue
			}
			if strings.Contains(v.InnerHtml(), "text-align: center;") {
				continue
			}
			//log.Print(detail.P)
			detail.P = append(detail.P, v.InnerHtml())
		}
		doc.Free()
	} else {
		log.Println(err)
	}
	return detail
}
コード例 #24
0
ファイル: shenzhentong.go プロジェクト: oupag/dev-for-go
func getPage(w http.ResponseWriter, r *http.Request) {
	url := "http://query.shenzhentong.com:8080/sztnet/qryCard.do?cardno="
	r.ParseForm()

	//如果不存在卡号
	if len(r.Form["cardno"]) <= 0 {
		return
	}
	url += r.Form["cardno"][0]

	var doc *goquery.Document
	var err error
	enc := mahonia.NewDecoder("gbk")
	if doc, err = goquery.NewDocument(url); err != nil {
		panic(err.Error())
	}

	var szt Szt
	var val string
	doc.Find(".tableact tr td").Each(func(i int, ss *goquery.Selection) {
		val = enc.ConvertString(ss.Text())

		switch i {
		case 1:
			szt.CardNumber, _ = strconv.Atoi(val)
		case 2:
			preg := `2[0-9-\s:]*`
			re, _ := regexp.Compile(preg)
			szt.BalanceTime = re.FindString(val)
		case 3:
			szt.CardBalance = val
		case 5:
			szt.CardValidity = val
		}
	})

	szt.CurrentTime = time.Now().Format("2006-01-02 15:04:05")
	res, _ := json.Marshal(szt)

	fmt.Fprintf(w, string(res)) //显示到网页
	fmt.Println(string(res))    //控制台显示
}
コード例 #25
0
ファイル: mmsdav1.go プロジェクト: qiangmzsx/golang
// 解析reply
func parserReply(reply *Reply) *ReturnMMSDA {
	dec := mahonia.NewDecoder("gbk")
	//初始化默认值
	sid := make([]int, 0)
	returnMMSDA := ReturnMMSDA{Status: 0, Msg: "", Sids: sid, Command: Command{Mode: 0, Url: "", Strategy: 0, Parsed_text: ""}}
	//判断MMSDA返回是否正确
	if len(reply.Result) > 0 && reply.Result[0].Normal.Danormalanalysis.Voiceguidesidentify.Is_fullreplace == true {
		query := dec.ConvertString(reply.Result[0].Normal.Danormalanalysis.Voiceguidesidentify.Fullreplace_query)
		returnMMSDA.Status = 0
		returnMMSDA.Msg = ""
		command := Command{}
		command.Mode = 2
		command.Url = "search://" + url.QueryEscape(query)
		command.Parsed_text = url.QueryEscape(query)
		command.Strategy = reply.Result[0].Normal.Danormalanalysis.Voiceguidesidentify.Strategy_type
		returnMMSDA.Command = command
	}

	return &returnMMSDA
}
コード例 #26
0
func (c *AppLogBiz) ReadFromTodayFile() {
	logs := make([]dtos.AppLogDto, 0, 10)
	// 取当前日期并格式化: 20160519
	date := time.Now().Format("20060102")
	websites := strings.Split(beego.AppConfig.String("websites"), "|")
	logtypes := strings.Split(beego.AppConfig.String("logtypes"), "|")
	for _, site := range websites {
		for _, logtype := range logtypes {
			logtype := strings.Split(logtype, ":")[0]
			path := filepath.Join(beego.AppConfig.String("logpath"), site, logtype)
			beego.Debug(path)
			// 读取目录下所有文件
			files, err := ioutil.ReadDir(path)
			helpers.HandleError(err)
			env := mahonia.NewDecoder("GBK")
			for _, v := range files {
				// 如果是文件,并且文件名包含当前日期
				if !v.IsDir() && strings.Contains(v.Name(), date) {
					file, err := os.OpenFile(path+"/"+v.Name(), 0, 0777)
					helpers.HandleError(err)
					rd := bufio.NewReader(file)
					for {
						line, _, err := rd.ReadLine()
						if err != nil || io.EOF == err {
							break
						}
						strLog := env.ConvertString(string(line))
						if strLog != "" {
							tmpLog := dtos.AppLogDto{}
							json.Unmarshal([]byte(strLog), &tmpLog)
							tmpLog.WebSite = site
							logs = append(logs, tmpLog)
						}
					}
					file.Close()
				}
			}
		}
	}
	save(logs)
}
コード例 #27
0
ファイル: GoldPrice.go プロジェクト: dengweiwen/WeiXin
func GoldPrice() string {
	strFormat := fmt.Sprintln("上海黄金交易所金价(仅供参考)")
	rep, err := http.Get("http://gold.hexun.com/hjxh/")
	if err != nil {
		return "数据获取失败"
	}
	defer rep.Body.Close()
	data, err := ioutil.ReadAll(rep.Body)
	if err != nil {
		return "数据获取失败"
	}
	m := mahonia.NewDecoder("GBK")
	s := m.ConvertString(string(data))
	re, _ := regexp.Compile(`<p>上海黄金交易所行情</p>[\s\S]*<span>上海黄金交易所</span>`)
	s = re.FindString(s)
	re, _ = regexp.Compile(`<tbody[^> ]*>[\s\S]*</tbody>`)
	s = re.FindString(s)
	re, _ = regexp.Compile(`<th>[\s\S]*</th>`)
	s = re.ReplaceAllString(s, "")
	s = strings.Replace(s, "<tr class=\"r\">", "<tr>", -1)
	s = strings.Replace(s, "<td class=\"l\"><span>", "<td>", -1)
	s = strings.Replace(s, "</span></td>", "</td>", -1)
	s = strings.Replace(s, "<tbody>", "", -1)
	s = strings.Replace(s, "</tbody>", "", -1)
	s = strings.Replace(s, "\r", "", -1)
	s = strings.Replace(s, "\n", "", -1)
	s = strings.Replace(s, "<tr>", "", -1)
	rows := strings.Split(s, "</tr>")
	for i := 0; i < len(rows); i++ {
		if len(rows[i]) > 50 {
			tr := strings.Replace(rows[i], "<td>", "", -1)
			cells := strings.Split(tr, "</td>")
			st := ShowPriceFormat(cells)
			if len(st) > 10 {
				strFormat += fmt.Sprint(st)
			}
		}
	}
	fmt.Println(strFormat)
	return strFormat
}
コード例 #28
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func printValue(pdu gosnmp.SnmpPDU) error {
	fmt.Printf("%s = ", pdu.Name)
	dec := mahonia.NewDecoder("gbk")
	switch pdu.Type {
	case gosnmp.OctetString:
		b := pdu.Value.([]byte)
		_, date, _ := dec.Translate(b, true)
		fmt.Printf("STRING: %s\n", string(date))
	case gosnmp.TimeTicks:
		b := gosnmp.ToBigInt(pdu.Value)
		t, _ := strconv.Atoi(fmt.Sprintf("%d", b))
		str_time := time.Unix(int64(t), 0).Format("Mon Jan 2 15:04:05.000 2006 +0800")
		fmt.Printf("TimeTicks: %d %s\n", b, str_time)
	case gosnmp.IPAddress:
		b := pdu.Value.(string)
		fmt.Printf("IpAddress: %s\n", string(b))
	default:
		fmt.Printf("TYPE %d: %d\n", pdu.Type, gosnmp.ToBigInt(pdu.Value))
	}
	return nil
}
コード例 #29
0
ファイル: main.go プロジェクト: idcos/osinstall-server
// 网卡名称
func getNicInterfaceIndex(mac string) string {
	var cmd = fmt.Sprintf(`wmic nic where (MACAddress="%s" AND netConnectionStatus=2) get InterfaceIndex /value`, mac)
	var r = `InterfaceIndex=(.*)`
	var output string
	utils.Logger.Debug(cmd)
	if outputBytes, err := utils.ExecCmd(scriptFile, cmd); err != nil {
		utils.Logger.Error(err.Error())
	} else {
		enc := mahonia.NewDecoder("gbk")
		output = enc.ConvertString(string(outputBytes))
		utils.Logger.Debug(output)
	}

	reg := regexp.MustCompile(r)
	var regResult = reg.FindStringSubmatch(output)
	if regResult == nil || len(regResult) != 2 {
		return ""
	}
	utils.Logger.Info("Nic Interface Index:" + regResult[1])
	// fmt.Println(strings.Trim(regResult[1], "\r\n"))
	return regResult[1]
}
コード例 #30
0
ファイル: main.go プロジェクト: idcos/osinstall-server
// DNS
func getDNS() string {
	var cmd = `echo | nslookup`
	var r = `Address:[:blank:]*(.+)`
	var output string
	utils.Logger.Debug(cmd)
	if outputBytes, err := utils.ExecCmd(scriptFile, cmd); err != nil {
		utils.Logger.Error(err.Error())
	} else {
		enc := mahonia.NewDecoder("gbk")
		output = enc.ConvertString(string(outputBytes))
		utils.Logger.Debug(output)
	}

	reg := regexp.MustCompile(r)
	var regResult = reg.FindStringSubmatch(output)
	if regResult == nil || len(regResult) != 2 {
		return ""
	}

	var dns = strings.TrimSpace(regResult[1])
	// fmt.Println(dns)
	return dns
}