Forráskód Böngészése

爬虫新增infoformat字段相关修改

maxiaoshan 2 éve
szülő
commit
360da3f858
3 módosított fájl, 26 hozzáadás és 17 törlés
  1. 19 13
      src/front/front.go
  2. 1 1
      src/spider/service.go
  3. 6 3
      src/timetask/timetask.go

+ 19 - 13
src/front/front.go

@@ -544,9 +544,16 @@ func (f *Front) ImportLua() {
 				if k != 0 {
 					cells := v.Cells
 					if cells[1].Value != "" {
+						code := cells[1].Value
+						query := map[string]interface{}{"code": cells[1].Value}
+						rs, _ := u.MgoEB.FindOne("import", query)
+						if len(*rs) > 0 {
+							errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫代码重复,请修改"
+							continue
+						}
 						o := make(map[string]interface{})
 						o["name"] = cells[0].Value
-						o["code"] = cells[1].Value
+						o["code"] = code
 						o["channel"] = cells[2].Value
 						channels := cells[3].Value
 						channels = strings.ReplaceAll(channels, ",", ",")
@@ -556,6 +563,7 @@ func (f *Front) ImportLua() {
 						one, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"href": href})
 						if len(*one) > 0 {
 							errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫" + cells[1].Value + ",该栏目已存在,请确认"
+							continue
 						}
 						o["channeladdr"] = href
 						o["author"] = cells[5].Value
@@ -582,25 +590,23 @@ func (f *Front) ImportLua() {
 						o["weight"] = weigh
 						//爬虫类型
 						infoformat, _ := cells[15].Int()
+						if infoformat < 1 {
+							errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫" + cells[1].Value + ",缺少爬虫类型信息"
+							continue
+						}
 						o["infoformat"] = infoformat
 						//存储表
 						o["coll"] = cells[16].Value
 						//table := cells[6].Value
 						//o["table"] = table
 						//o["transfercode"] = qu.IntAll(Transfercode[table])
-						query := map[string]interface{}{"code": cells[1].Value}
-						rs, _ := u.MgoEB.FindOne("import", query)
-						if len(*rs) > 0 {
-							errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行重复,已经过滤"
+						ok, name := saveLua(o) //保存爬虫
+						if ok == false {
+							errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行找不到作者,已经过滤"
 						} else {
-							ok, name := saveLua(o) //保存爬虫
-							if ok == false {
-								errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行找不到作者,已经过滤"
-							} else {
-								o["author"] = name
-								o["importuser"] = f.GetSession("username")
-								u.MgoEB.Save("import", o)
-							}
+							o["author"] = name
+							o["importuser"] = f.GetSession("username")
+							u.MgoEB.Save("import", o)
 						}
 					}
 				}

+ 1 - 1
src/spider/service.go

@@ -87,7 +87,7 @@ func GetScript(code string, str ...interface{}) (script, script_list, script_con
 		} else {
 			script_content = (*lua)["str_content"].(string)
 		}
-		script += fmt.Sprintf(util.Tmp_Other, (*lua)["spidertype"], (*lua)["spiderhistorymaxpage"], (*lua)["spidermovevent"], (*lua)["spidercompete"])
+		script += fmt.Sprintf(util.Tmp_Other, (*lua)["spidertype"], (*lua)["spiderhistorymaxpage"], (*lua)["spidermovevent"], (*lua)["spidercompete"], (*lua)["infoformat"])
 		script += ` 
 			` + script_time + `
 			` + script_list + `

+ 6 - 3
src/timetask/timetask.go

@@ -192,10 +192,10 @@ func SpiderMoveEvent() {
 			var upresult bool
 			var err error
 			set := map[string]interface{}{}
-			qu.Debug("lua move:", code, event)
+			qu.Debug("lua move:", code, event, spidertype, (*lua)["state"])
 			if spidertype == "history" {
 				newevent := GetEvent(code, (*lua))
-				qu.Debug("new event:", newevent)
+				qu.Debug(code, " new event:", newevent)
 				set["event"] = newevent
 				set["spidertype"] = "increment"
 				//type_content, _ := (*lua)["type_content"].(int)
@@ -207,8 +207,11 @@ func SpiderMoveEvent() {
 				//	set["str_content"] = str_recontent
 				//	set["str_recontent"] = str_content
 				//}
-				if util.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": set}, false, false) {
+				upOk := util.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": set}, false, false)
+				qu.Debug(code, "脚本更新成功:", upOk)
+				if upOk {
 					upresult, err = spider.UpdateSpiderByCodeState(code, "5", newevent) //脚本上架
+					qu.Debug(code, "脚本上架", upresult, err)
 				}
 			}
 			ok := false