From c44217b13bf649b31608808cb783c00d9e899529 Mon Sep 17 00:00:00 2001 From: Rorical <46294886+Rorical@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:20:36 +0100 Subject: [PATCH] feat: add custom date flag --- tasks.go | 16 ++++++++++++++-- tools/incrementor/incrementor.go | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tasks.go b/tasks.go index 975e5d3..209ded2 100644 --- a/tasks.go +++ b/tasks.go @@ -10,6 +10,7 @@ import ( "github.com/ShugetsuSoft/pixivel-back/modules/responser/task" "github.com/ShugetsuSoft/pixivel-back/tools/incrementor" "log" + "time" ) func main() { @@ -17,7 +18,10 @@ func main() { defer cancel() var configPath string + var date string flag.StringVar(&configPath, "config", "config.yaml", "Config File Path") + flag.StringVar(&date, "date", "", "Specify rank date") + flag.Parse() conf, err := modules.ReadConfig(configPath) @@ -49,8 +53,16 @@ func main() { ope := operations.NewDatabaseOperations(ctx, db, ft, es, ndb) taskgen := task.NewTaskGenerator(mq, config.CrawlTaskQueue, conf.General.SpiderRetry, tracer) - - err = incrementor.CrawlRank(taskgen, ope) + var dateobj time.Time + if date != "" { + dateobj = time.Now().AddDate(0, 0, -2) + } else { + dateobj, err = time.Parse("20060102", date) + if err != nil { + log.Fatal(err) + } + } + err = incrementor.CrawlRank(taskgen, ope, dateobj) if err != nil { log.Fatal(err) } diff --git a/tools/incrementor/incrementor.go b/tools/incrementor/incrementor.go index 6060868..e451317 100644 --- a/tools/incrementor/incrementor.go +++ b/tools/incrementor/incrementor.go @@ -8,7 +8,7 @@ import ( "github.com/ShugetsuSoft/pixivel-back/modules/responser/task" ) -func CrawlRank(taskgen *task.TaskGenerator, ope *operations.DatabaseOperations) error { +func CrawlRank(taskgen *task.TaskGenerator, ope *operations.DatabaseOperations, date time.Time) error { ctx := context.Background() contents := map[string][]string{ @@ -17,7 +17,7 @@ func CrawlRank(taskgen *task.TaskGenerator, ope *operations.DatabaseOperations) "manga": {"daily", "weekly", "monthly", "rookie"}, "ugoira": {"daily", "weekly"}, } - today := time.Now().AddDate(0, 0, -2).Format("20060102") + today := date.Format("20060102") for content := range contents { for index := range contents[content] { exist, err := ope.IsRankExist(ctx, contents[content][index], today, content)