فهرست منبع

验证码服务添加统计;修改获取发布时间工具类

maxiaoshan 2 سال پیش
والد
کامیت
ab06564624
3فایلهای تغییر یافته به همراه30 افزوده شده و 8 حذف شده
  1. 23 0
      src/analysiscode/server.go
  2. 2 4
      src/spiderutil/clean.go
  3. 5 4
      src/spiderutil/publishtime.go

+ 23 - 0
src/analysiscode/server.go

@@ -12,6 +12,7 @@ import (
 	"os"
 	"qfw/util"
 	"spiderutil"
+	"sync/atomic"
 	"time"
 
 	"github.com/imroc/req"
@@ -26,9 +27,12 @@ type CodeService struct {
 	proto.GetCodeServer
 }
 
+var PyTimes int64
+
 //server
 func main() {
 	util.Debug("port", spiderutil.Config.ServerPort)
+	go CountPyTimes() //统计使用超级鹰次数
 	lis, err := net.Listen("tcp", spiderutil.Config.ServerPort)
 	if err != nil {
 		util.Debug("failed to listen: ", err)
@@ -164,6 +168,7 @@ func getCodeByPay(path, stype, head, cookie string) (code string, respheader htt
 		json.Unmarshal([]byte(cookie), &cookies)
 	}
 	for times := 1; times <= 2; times++ { //重试三次
+		atomic.AddInt64(&PyTimes, 1)
 		if times > 1 { //重试第2次开始,使用代理ip
 			proxyIp := spiderutil.GetProxyAddr(spiderutil.Config.ProxyAddr, spiderutil.Config.ProxyAuthor) //获取代理地址
 			util.Debug("proxy:", proxyIp)
@@ -235,6 +240,24 @@ func savefile(url string, resp *req.Response) {
 	}
 }
 
+func CountPyTimes() {
+	go func() {
+		for {
+			if time.Now().Hour() == 0 {
+				util.Debug("当天共使用超级鹰次数:", PyTimes)
+				PyTimes = 0
+				time.Sleep(1 * time.Hour)
+			} else {
+				time.Sleep(10 * time.Minute)
+			}
+		}
+	}()
+	for {
+		time.Sleep(1 * time.Minute)
+		util.Debug("当前使用超级鹰次数:", PyTimes)
+	}
+}
+
 //func main() {
 //	log.Println(util.Config)
 //	conn, err := grpc.Dial("127.0.0.1"+util.Config.Port, grpc.WithInsecure())

+ 2 - 4
src/spiderutil/clean.go

@@ -11,23 +11,21 @@ import (
 	"image"
 	"image/color"
 	"math"
-	mu "mfw/util"
 	"os"
+	qu "qfw/util"
 	"strings"
 
 	"github.com/disintegration/imaging"
 	"github.com/donnie4w/go-logger/logger"
 )
 
-var client *mu.Client
-
 const (
 	white, black = uint8(0xff), uint8(0x00)
 )
 
 //获取验证码
 func GetEcpsCode(area string, img []byte) (code, state string) {
-	defer mu.Catch()
+	defer qu.Catch()
 	var err error
 	var bs []byte
 	area = strings.ToUpper(area)

+ 5 - 4
src/spiderutil/publishtime.go

@@ -60,15 +60,16 @@ func GetPublishtime(textArr []string) string {
 
 func GetPublishtimeByText(text string) (int64, bool) {
 	defer util.Catch()
+	text = FilterReg.ReplaceAllString(text, "")   //去除html标签
+	text = FilterReg2.ReplaceAllString(text, "")  //去除字母
+	text = RegEndSpace.ReplaceAllString(text, "") //去除结尾空格
+	text = RegSpace.ReplaceAllString(text, "")    //去除空格
 	runeDetail := []rune(text)
 	length := len(runeDetail)
 	if length < 30 {
 		return int64(0), false
 	}
-	text = FilterReg.ReplaceAllString(text, "")   //去除html标签
-	text = FilterReg2.ReplaceAllString(text, "")  //去除字母
-	text = RegEndSpace.ReplaceAllString(text, "") //去除结尾空格
-	text = RegSpace.ReplaceAllString(text, "")    //去除空格
+
 	result := text
 	if length > 70 {
 		result = string(runeDetail[length-70:])