加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 3.82 KB
一键复制 编辑 原始数据 按行查看 历史
Song Ziyangyi 提交于 2020-10-26 15:53 . init
package main
import (
"fmt"
"log"
"github.com/spf13/cobra"
"go.uber.org/zap"
"yuemiao/config"
"yuemiao/jin_niu"
"yuemiao/seckill"
"yuemiao/yuemiao"
)
var (
cfgFile string
)
func yuemiaoCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "yuemiao",
Short: "启动约苗九价脚本",
Long: "启动约苗九价脚本",
RunE: func(cmd *cobra.Command, args []string) error {
s := yuemiao.NewYueMiao(zap.L(), config.C.YueMiao)
s.V2()
zap.L().Info("yuemiao")
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
serverCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
return serverCmd
}
func vcodeCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "vcode",
Short: "验证码相关命令",
Long: "验证码相关命令",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
serverCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
serverCmd.AddCommand(getVcodeCmd())
serverCmd.AddCommand(parseVcodeCmd())
return serverCmd
}
func getVcodeCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "get",
Short: "获取所有验证码",
Long: "获取所有验证码",
Run: func(cmd *cobra.Command, args []string) {
s := yuemiao.NewYueMiao(zap.L(), config.C.YueMiao)
err := s.GetAllVCode()
if err != nil {
fmt.Printf("获取所有验证码失败:%s\n", err.Error())
}
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
return serverCmd
}
func parseVcodeCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "parse",
Short: "解析所有验证码",
Long: "解析所有验证码",
Run: func(cmd *cobra.Command, args []string) {
s := yuemiao.NewYueMiao(zap.L(), config.C.YueMiao)
err := s.ParseAllVCode()
if err != nil {
fmt.Printf("解析所有验证码失败:%s\n", err.Error())
}
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
return serverCmd
}
func yuemiaoSeckillCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "seckill",
Short: "查看约苗有哪些城市有秒杀信息",
Long: "查看约苗有哪些城市有秒杀信息",
RunE: func(cmd *cobra.Command, args []string) error {
config.C.YueMiao.Verbose = false
s := seckill.NewAllSteps(zap.L(), config.C.YueMiao)
cities, err := s.GetSeckillCities()
if err != nil {
fmt.Printf("查看约苗有哪些城市有秒杀信息有误:%s\n", err.Error())
}
fmt.Printf("明天可以秒杀的城市有:%s\n", cities)
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
serverCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
return serverCmd
}
func jinniuCmd() *cobra.Command {
serverCmd := &cobra.Command{
Use: "jinniu",
Short: "启动金牛公众号九价脚本",
Long: "启动金牛公众号九价脚本",
RunE: func(cmd *cobra.Command, args []string) error {
zap.L().Info("jinniu")
j := jin_niu.NewJinNiu(zap.L(), config.C.JinNiu)
j.Together()
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
config.Init(cfgFile)
return nil
},
}
serverCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
return serverCmd
}
var RootCmd cobra.Command = cobra.Command{
Use: "jiujia",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}
func main() {
RootCmd.AddCommand(yuemiaoCmd())
RootCmd.AddCommand(jinniuCmd())
RootCmd.AddCommand(yuemiaoSeckillCmd())
// RootCmd.AddCommand(vcodeCmd())
if err := RootCmd.Execute(); err != nil {
log.Fatalln(err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化