forked from xjblszyy/JiuJia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
163 lines (146 loc) · 3.82 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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)
}
}