Skip to content

Commit

Permalink
feat: add custom date flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Rorical committed Oct 17, 2023
1 parent 12fb665 commit c44217b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import (
"github.com/ShugetsuSoft/pixivel-back/modules/responser/task"
"github.com/ShugetsuSoft/pixivel-back/tools/incrementor"
"log"
"time"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
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)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions tools/incrementor/incrementor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down

0 comments on commit c44217b

Please sign in to comment.