pcgamedb/cmd/organize.go
nite07 434dbb1dc2
All checks were successful
docker / prepare-and-build (push) Successful in 2m37s
release / goreleaser (push) Successful in 24m0s
refactor DeduplicateGameItems
update games.json
2024-11-22 01:30:26 +08:00

43 lines
955 B
Go

package cmd
import (
"pcgamedb/crawler"
"pcgamedb/db"
"pcgamedb/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var organizeCmd = &cobra.Command{
Use: "organize",
Long: "Organize game info by repack game's name",
Short: "Organize game info by repack game's name",
Run: organizeRun,
}
type organizeCommandConfig struct {
Num int
}
var organizeCmdCfg organizeCommandConfig
func init() {
organizeCmd.Flags().IntVarP(&organizeCmdCfg.Num, "num", "n", -1, "number of items to process")
RootCmd.AddCommand(organizeCmd)
}
func organizeRun(cmd *cobra.Command, args []string) {
games, err := db.GetUnorganizedGameItems(organizeCmdCfg.Num)
if err != nil {
log.Logger.Error("Failed to get games", zap.Error(err))
}
for _, game := range games {
err := crawler.OrganizeGameItem(game)
if err != nil {
log.Logger.Error("failed to organize game item")
}
log.Logger.Info("game item organized", zap.String("name", game.Name))
}
}