-
Notifications
You must be signed in to change notification settings - Fork 1
/
autocheckin.go
102 lines (90 loc) · 2.62 KB
/
autocheckin.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
package main
import (
"flag"
"github.com/chucklqsun/glog"
"sync"
)
var w sync.WaitGroup
func login(vendorName string, account string) bool {
aa, err := readAccount("account")
if err != nil {
glog.Errorln("Account err:", err)
return false
}
username := aa[vendorName+"."+account]["username"]
password := aa[vendorName+"."+account]["password"]
login_req := aci_request{
account: account,
url: myVendor.config[vendorName]["url_login"].(string),
proxy: myVendor.config[vendorName]["proxy"].(string),
method: myVendor.config[vendorName]["method"].(string),
head: myVendor.config[vendorName]["head"].(aci_head).data,
body: myVendor.config[vendorName]["body_login"].(func(string, string, string) string)(username, password, account),
cookie: "",
result: myVendor.config[vendorName]["result_login"],
}
if login_req.body != "" {
return login_req.sendRequest()
}
return true
}
func checkin(vendorName string, account string) bool {
//todo: load cookie file in run dir now, auto loading in the further
var (
cookie_err error
cookie string
)
cookie, cookie_err = readCookie(vendorName + "." + account + ".cookie")
if cookie_err != nil {
glog.Errorln("Cookie err:", cookie_err)
return false
}
checkin_req := aci_request{
account: account,
url: myVendor.config[vendorName]["url_checkin"].(string),
proxy: myVendor.config[vendorName]["proxy"].(string),
method: myVendor.config[vendorName]["method"].(string),
head: myVendor.config[vendorName]["head"].(aci_head).data,
body: myVendor.config[vendorName]["body_checkin"].(func(string) string)(cookie),
cookie: cookie,
result: myVendor.config[vendorName]["result_checkin"],
}
return checkin_req.sendRequest()
}
func controller(vendorName string, account string) {
mode := myVendor.config[vendorName]["mode"].(int)
switch mode {
case 1:
login(vendorName, account)
case 2:
checkin(vendorName, account)
case 3:
if !checkin(vendorName, account) {
login(vendorName, account) //current not support duokan due to capt
checkin(vendorName, account)
}
}
w.Done()
}
func main() {
//initial command for log
flag.Parse()
flag.Lookup("log_dir").Value.Set("./")
flag.Lookup("log_name").Value.Set("log")
flag.Lookup("alsologtostderr").Value.Set("true")
glog.Info("Starting ...")
for key, _ := range myVendor.config {
if myVendor.config[key]["status"].(int) == 0 {
continue
}
for _, account := range myVendor.config[key]["account"].([]string) {
w.Add(1)
go controller(key, account)
glog.Infoln("Job -> ", key, ":", account)
}
}
w.Wait()
glog.Info("End")
//make sure log msg flush into file
glog.Flush()
}