Эх сурвалжийг харах

大商所指标ID爬取规则修改

xingzai 3 жил өмнө
parent
commit
f6c484272d

+ 15 - 17
services/commodity_trade_dalian.go

@@ -29,7 +29,8 @@ type SearchContractId struct {
 
 //同步 N天 之内的数据
 func SyncRankingFromDalianDo() {
-	for i := 182; i >= 0; i-- {
+	for i := 180; i >= 0; i-- {
+		//time.Sleep(time.Duration(1) * time.Second)
 		SyncRankingFromDalianSearch(i)
 	}
 }
@@ -68,8 +69,8 @@ func SyncRankingFromDalianSearch(dayNum int) (err error) {
 	for _, v := range list {
 		listDataMap[v.DealShortName+v.ClassifyType+v.DataTime] = v.BaseFromTradeDalianIndexId
 	}
-	//n := utils.GetRandInt(10, 120)
-	//time.Sleep(time.Duration(n) * time.Second)
+	n := utils.GetRandInt(10, 120)
+	time.Sleep(time.Duration(n) * time.Second)
 
 	var ContractId string
 	var CarietyCode string
@@ -123,11 +124,11 @@ func SyncRankingFromDalianSearch(dayNum int) (err error) {
 		item.ListSearch = listContractId
 		items = append(items, item)
 	}
-	for k, v := range items {
-		for _, v2 := range v.ListSearch {
-			fmt.Println(currDate, v.VarietyName, v2.ContractId, v.CarietyCode, k)
-		}
-	}
+	//for k, v := range items {
+	//	for _, v2 := range v.ListSearch {
+	//		fmt.Println(currDate, v.VarietyName, v2.ContractId, v.CarietyCode, k)
+	//	}
+	//}
 	SyncRankingFromDalian(dayNum, items)
 	return err
 }
@@ -251,13 +252,11 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 	var rank, shortName, dealValue, dealChange, buyName, buyValue, buyChange, soldName, soldValue, soldChange string
 	table.Find("tr").Each(func(i int, tr *goquery.Selection) {
 		tds := tr.Find("td")
-		fmt.Println(tds.Length(), "长度:", i)
+		//fmt.Println(tds.Length(), "长度:", i)
 		if tds.Length() == 0 || tds.Length() == 7 {
-			if i == 23 {
-				tdText := tds.Text()
-				utils.FileLog.Info(tdText)
-			}
-		} else if i == 23 {
+			tdText := tds.Text()
+			utils.FileLog.Info(tdText)
+		} else {
 			item := new(models.BaseFromTradeDalianIndex)
 			tds.Each(func(tk int, td *goquery.Selection) {
 				tdText := td.Text()
@@ -355,7 +354,6 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 					item.SoldCode = GetIndexCodeGeneratorPinYing("top20", item.SoldName, contractId, "sold", "DL")
 				}
 			}
-			fmt.Println(item)
 			if val, ok := listDataMap[item.DealShortName+item.ClassifyType+item.DataTime]; !ok {
 				addSql += models.GetAddSql(item)
 				isAdd = true
@@ -398,11 +396,11 @@ func GetIndexCodeGeneratorPinYing(shortName, indexName, contractCode, suffix, ex
 	if shortName == "top20" {
 		indexCode = "top20" + contractCode + suffix
 	} else {
-		//取公司前四个字的全拼
+		//取公司的全拼
 		a := pinyin.NewArgs()
 		rows := pinyin.Pinyin(shortName, a)
 		strResult := ""
-		for i := 0; i < len(rows[:4]); i++ {
+		for i := 0; i < len(rows); i++ {
 			if len(rows[i]) != 0 {
 				strResult += rows[i][0]
 			}