Browse Source

更新 热门项目

wcc 1 year ago
parent
commit
1e474d1f73
2 changed files with 35 additions and 6 deletions
  1. 19 6
      website_columns/main.go
  2. 16 0
      website_columns/web_test.go

+ 19 - 6
website_columns/main.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/net/gclient"
-	"github.com/gogf/gf/v2/os/gtime"
 	"github.com/robfig/cron/v3"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
@@ -158,11 +157,25 @@ func getHot() {
 		}
 	}
 
-	file := gtime.Now().AddDate(0, 0, -1).Format("Y-m-d")
-	res := gclient.New().GetContent(context.Background(), "http://172.17.145.164:18880/jyartvisit/"+file+".res")
-	//res := gclient.New().GetContent(context.Background(), "http://127.0.0.1:50080/jyartvisit/"+file+".res")
-	arrs := strings.Split(res, "\n")
-	for _, v := range arrs {
+	getRes := make([]string, 0)
+	end := time.Date(2023, 12, 5, 0, 0, 0, 0, time.Local)
+	now := time.Now()
+	var recentDays []string
+	for i := 0; i < 15; i++ {
+		day := now.AddDate(0, 0, -i)
+		// 如果日期在 2023-12-05 及之后,则添加到 recentDays
+		if !day.Before(end) {
+			recentDays = append(recentDays, day.Format("2006-01-02"))
+		}
+	}
+
+	for _, v := range recentDays {
+		res := gclient.New().GetContent(context.Background(), "http://172.17.145.164:18880/jyartvisit/"+v+".res")
+		arrs := strings.Split(res, "\n")
+		getRes = append(getRes, arrs...)
+	}
+
+	for _, v := range getRes {
 		vs := strings.Split(v, " ")
 		if len(vs) == 2 {
 			insert := map[string]interface{}{

+ 16 - 0
website_columns/web_test.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 	"testing"
+	"time"
 )
 
 func TestIdTime(T *testing.T) {
@@ -12,4 +13,19 @@ func TestIdTime(T *testing.T) {
 	timestamp := objectID.Timestamp()
 
 	fmt.Println(timestamp.Format("2006-01-02"))
+	fmt.Println("=============")
+
+	end := time.Date(2023, 12, 5, 0, 0, 0, 0, time.Local)
+	now := time.Now()
+	var recentDays []string
+	for i := 0; i < 15; i++ {
+		day := now.AddDate(0, 0, -i)
+		// 如果日期在 2023-12-05 及之后,则添加到 recentDays
+		if !day.Before(end) {
+			recentDays = append(recentDays, day.Format("2006-01-02"))
+		}
+	}
+
+	fmt.Println(recentDays)
+
 }