示例#1
0
文件: a3.go 项目: enderlu/vfp
func main() {

	zser_b, _ := vfp.Filetostr(zpath + "service.txt")

	var displayName = "check word from page"
	var desc = "check word from page."
	var ws, err = service.NewService(readStr(zser_b), displayName, desc)

	if err != nil {
		fmt.Printf("%s unable to start: %s", displayName, err)
		return
	}

	if len(os.Args) > 1 {
		var err error
		verb := os.Args[1]
		switch verb {
		case "install":
			err = ws.Install()
			if err != nil {
				fmt.Printf("Failed to install: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" installed.\n", displayName)
		case "remove":
			err = ws.Remove()
			if err != nil {
				fmt.Printf("Failed to remove: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" removed.\n", displayName)
		}
		return
	}
	err = ws.Run(func() error {
		// start
		go doWork()
		ws.LogInfo("I'm Running!")
		return nil
	}, func() error {
		// stop
		stopWork()
		ws.LogInfo("I'm Stopping!")
		return nil
	})
	if err != nil {
		ws.LogError(err.Error())
	}
}
示例#2
0
文件: checkc.go 项目: enderlu/vfp
func DisplayUrl(zurl string) {

	for {
		fmt.Println("\nchecking ...", zurl)
		r, err1 := http.Get(zurl)

		zcode := vfp.Strextract(r.Header["Content-Type"][0], "charset=", "charset=", 1)
		zcode = vfp.Lower(zcode)
		switch zcode {
		case "gbk", "gb2312", "gb18030":
			zcode = "gb18030"
		default:
			zcode = "utf8"
		}
		checkError(err1)
		fmt.Println("search status :", func() string {
			if r.StatusCode == 200 {
				return "OK"
			}
			return string(r.StatusCode)
		}())

		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)
		}
		decoder := mahonia.NewDecoder(zcode)
		_, buf_line, _ := decoder.Translate(buf, true)

		zfound := false
		zwords := vfp.Aline(zw)
		zv := ""
		zfound_word := ""
		znot_found := ""
		//zh, zn := 0, 0
		zset := false
		znew_found := ""
		znew_set := false

		for _, zv = range zwords {
			//zh++
			if zv == "" {
				continue
			}
			if At(zv, string(buf_line)) > 0 {
				_, zok := zfindMap[zv]
				if !zok {
					if znew_set {
						znew_found = znew_found + "," + zv
					} else {
						znew_found = znew_found + zv
					}
					znew_set = true
					zfindMap[zv] = zv
				} else {
					if zfound {
						zfound_word = zfound_word + "," + zv
					} else {
						zfound_word = zfound_word + zv
					}

				}
				zfound = true

				//zn++
			} else {
				if zset {
					znot_found = znot_found + "," + zv
				} else {
					znot_found = znot_found + zv
				}
				zset = true
			}
		}

		//zmind := ""

		//if znot_found != "" {
		//	zmind = "未找到:" + znot_found + "\n未找全,隔10分钟继续下一轮查找\n"
		//} else {
		//	zmind = "已经找全了,隔10分钟继续下一轮查找\n"
		//}

		if znew_set && zfound {
			fmt.Println("found! ", zv)
			go PlaySound(zsound)

			zuin_b, _ := vfp.Filetostr(zpath + "uin.txt")
			zun_b, _ := vfp.Filetostr(zpath + "un.txt")
			zpass_b, _ := vfp.Filetostr(zpath + "pass.txt")

			SendQQMsg(readStr(zuin_b), readStr(zpass_b), readStr(zun_b),
				"新找到: "+znew_found+" \n"+
					"已找到: "+zfound_word+" \n"+
					"未找到: "+znot_found+" \n")

			//SendQQMsg(readStr(zuin_b), readStr(zpass_b), readStr(zun_b),
			//	"x6.GoLang~\n"+
			//		fmt.Sprintf("%v\n", vfp.Datetime())+
			//		"找到: "+zfound_word+" \n"+
			//		zmind+
			//		`url: `+html.EscapeString(zurl))

			//MessageBox("查找结果", "找到了\n"+zw, 0)
			//if zn == zh {
			//	break
			//}

		} else {
			fmt.Println("can not find ", zw)
		}
		time.Sleep(10 * 60 * time.Second)
	}

}