ziwen před 3 roky
rodič
revize
e47f772f07

+ 26 - 27
services/commodity_coal_coastal.go

@@ -11,7 +11,7 @@ import (
 	"time"
 )
 
-func FileCoalCoastal() () {
+func FileCoalCoastal() {
 	var err error
 	defer func() {
 		if err != nil {
@@ -20,35 +20,34 @@ func FileCoalCoastal() () {
 		}
 	}()
 	//path := "static/file/沿海八省动力煤终端用户供耗存数据更新03.07.xlsx"
-	var month string
+	var month, day string
 	dateMonth := int(time.Now().Month())
 	if dateMonth < 10 {
 		month = strconv.Itoa(dateMonth)
-		month = "0"+month
+		month = "0" + month
 	}
 
-	path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新04.04.xlsx"
-	//path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新%s.%s.xlsx"
-	//for i := 0;i < 7;i++{
-	//	dateDay := time.Now().AddDate(0,0,-i).Day()
-	//	if dateDay < 10 {
-	//		day = strconv.Itoa(dateDay)
-	//		day = "0"+day
-	//	}else {
-	//		day = strconv.Itoa(dateDay)
-	//	}
-	//	npath := fmt.Sprintf(path, month, day)
-	//	fmt.Println(npath)
-	//	exist,err := PathExists(npath)
-	//	if err != nil {
-	//		fmt.Println(err)
-	//		return
-	//	}
-	//	if exist{
-	//		path = npath
-	//		break
-	//	}
-	//}
+	path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新%s.%s.xlsx"
+	for i := 0; i < 7; i++ {
+		dateDay := time.Now().AddDate(0, 0, -i).Day()
+		if dateDay < 10 {
+			day = strconv.Itoa(dateDay)
+			day = "0" + day
+		} else {
+			day = strconv.Itoa(dateDay)
+		}
+		npath := fmt.Sprintf(path, month, day)
+		fmt.Println(npath)
+		exist, err := PathExists(npath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		if exist {
+			path = npath
+			break
+		}
+	}
 
 	xlFile, err := xlsx.OpenFile(path)
 	if err != nil {
@@ -136,7 +135,7 @@ func FileCoalCoastal() () {
 						mappingItems = append(mappingItems, &item)
 					}
 					if k == 10 {
-						unit = strings.Replace(cell.String(),"单位:","",-1)
+						unit = strings.Replace(cell.String(), "单位:", "", -1)
 					}
 				}
 			}
@@ -175,7 +174,7 @@ func FileCoalCoastal() () {
 			codeMap[v.IndexName] = v.IndexCode
 			newId, err := models.AddBaseFromCoalmineMapping(v)
 			if err != nil {
-				for i := 0; i<10; i++ {
+				for i := 0; i < 10; i++ {
 					v.IndexCode = v.IndexCode + strconv.Itoa(i)
 					codeMap[v.IndexName] = v.IndexCode
 					newId, err := models.AddBaseFromCoalmineMapping(v)

+ 16 - 14
services/commodity_coal_inland.go

@@ -19,20 +19,22 @@ func FileCoalInland() () {
 		}
 	}()
 	//path := "static/file/内陆17省动力煤终端用户供耗存20220322.xlsx"
-	path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存%s.xlsx"
-	for i := 0;i < 7;i++{
-		npath := fmt.Sprintf(path,time.Now().AddDate(0,0,-i).Format(utils.FormatDateUnSpace))
-		fmt.Println(npath)
-		exist,err := PathExists(npath)
-		if err != nil {
-			fmt.Println(err)
-			return
-		}
-		if exist{
-			path = npath
-			break
-		}
-	}
+	//path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存%s.xlsx"
+	path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存0406.xlsx"
+	//path := "/home/code/python/coal_mail/emailFile/内陆17省动力煤终端用户供耗存0331.xlsx"
+	//for i := 0;i < 7;i++{
+	//	npath := fmt.Sprintf(path,time.Now().AddDate(0,0,-i).Format(utils.FormatDateUnSpace))
+	//	fmt.Println(npath)
+	//	exist,err := PathExists(npath)
+	//	if err != nil {
+	//		fmt.Println(err)
+	//		return
+	//	}
+	//	if exist{
+	//		path = npath
+	//		break
+	//	}
+	//}
 	xlFile, err := xlsx.OpenFile(path)
 	if err != nil {
 		fmt.Println(err)

+ 1 - 1
services/task.go

@@ -10,7 +10,7 @@ func Task() {
 	fmt.Println("start crawler")
 	refreshData := task.NewTask("refreshData", "0 0,30 16-20 * * *", RefreshData)
 	refreshEic := task.NewTask("refreshData", "0 0 1,6 * * *", RefreshEic)
-	refreshCoal := task.NewTask("refreshData", "0 7 15 * * *", RefreshCoal)
+	refreshCoal := task.NewTask("refreshData", "0 13 15 * * *", RefreshCoal)
 	task.AddTask("数据爬取", refreshData)
 	task.AddTask("欧洲天然气爬取", refreshEic)
 	task.AddTask("中国煤炭网爬取", refreshCoal)