This commit is contained in:
toom1996
2026-08-11 00:49:59 +08:00
parent cab1023ba1
commit 3afd10e049
9 changed files with 268 additions and 151 deletions

View File

@ -1,44 +1,36 @@
package cmd
import (
"log"
"github.com/spf13/cobra"
"my-spiders/internal/config"
"my-spiders/internal/spider"
)
var (
brandID int64
forceUpdate bool
onlyPlatform bool
maxCo int
)
var vogueCmd = &cobra.Command{
Use: "vogue",
Short: "自动采集 vogue.com 网站发布会数据",
Short: "启动 Vogue 时装发布会采集器",
Run: func(cmd *cobra.Command, args []string) {
log.Println("[Command] 启动 Vogue 采集指令...")
// 1. 修复参数数量 & 类型强转 uint(brandID)
vogueSpider := spider.NewVogueSpider(DB, maxCo, uint(brandID), onlyPlatform)
// 从全局 YAML 配置中获取并发数
maxCo := config.GlobalConfig.App.MaxCo
vogueSpider := spider.NewVogueSpider(DB, maxCo)
vogueSpider.BrandID = brandID
vogueSpider.ForceUpdate = forceUpdate
vogueSpider.OnlyPlatform = onlyPlatform
vogueSpider.Debug = config.GlobalConfig.App.Debug // 赋值 Debug 状态
vogueSpider.Execute()
// 2. 修复方法名:将 Execute() 改为 Run()
vogueSpider.Run()
},
}
func init() {
rootCmd.AddCommand(vogueCmd)
vogueCmd.Flags().Int64VarP(&brandID, "brandId", "b", 0, "指定的品牌id.")
vogueCmd.Flags().BoolVarP(&forceUpdate, "forceUpdate", "f", false, "是否对已经保存的数据进行强制更新.")
vogueCmd.Flags().BoolVarP(&onlyPlatform, "onlyPlatform", "o", false, "是否只对当前平台品牌更新.")
}
// 绑定命令行参数
vogueCmd.Flags().Int64VarP(&brandID, "brand", "b", 0, "指定抓取的品牌 ID")
vogueCmd.Flags().BoolVarP(&onlyPlatform, "only-platform", "p", false, "是否仅抓取平台关联品牌")
// 修复:将 "c" 改为 "m"(或者 ""),避免与全局的 -c 参数冲突
vogueCmd.Flags().IntVarP(&maxCo, "max-co", "m", 5, "最大并发数限制")
}