-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
115 lines (106 loc) · 2.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
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"selfreport/cntime"
"selfreport/core/login"
"selfreport/core/message"
"selfreport/core/selfreport"
"selfreport/core/tmrreport"
"strings"
"gopkg.in/yaml.v2"
)
type CONF struct {
Users []struct {
Name string `yaml:"name"`
PassWord string `yaml:"password"`
TmrOutReport bool `yaml:"TmrOutReport"`
ChuXiaoReason string `yaml:"ChuXiaoReason"`
AddressQu string `yaml:"AddressQu"`
AddressDetails string `yaml:"AddressDetails"`
} `yaml:"Users"`
}
func setLogger(file string) (*os.File, error) {
f, err := os.OpenFile("log.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
if err != nil {
return nil, err
}
multiWriter := io.MultiWriter(os.Stdout, f)
log.SetOutput(multiWriter)
log.SetFlags(log.Ldate | log.Ltime)
return f, nil
}
func main() {
f, err := setLogger("log.log")
if err != nil {
log.Fatal(fmt.Errorf("设置日志流出错", err))
}
defer f.Close()
log.Println(os.Getwd())
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
if !strings.Contains(ex, "exe\\main.exe") && !strings.Contains(ex, "___go_build_main_go.exe") {
os.Chdir(exPath)
}
log.Println(`本项目仅作为免费的网络研究使用,
不得利用本程序以任何方式直接或者间接的从事违反中国法律、国际公约以及社会公德的行为,
!!!不支持进行虚假填报!!!
`)
conf, err := ioutil.ReadFile("Configuration/AccountList.yaml")
if err != nil {
panic(fmt.Errorf("配置文件打开错误 %v", err))
}
cntime.PrintNow()
var CONF = new(CONF)
err = yaml.Unmarshal(conf, CONF)
if err != nil {
panic(fmt.Errorf("yaml解析错误 %v", err))
}
for _, user := range CONF.Users {
log.Println(user.Name)
usc := &login.UserClient{}
usc.Init(user.Name, user.PassWord) //请填入学号,密码
client, err := usc.GetLoginedClient()
if err != nil {
log.Printf("学号%v 登陆错误", user.Name)
log.Println(err)
continue
}
msgclient := &message.Messageclient{Client: client}
msgclient.VisitUnreadMessage()
srclient := &selfreport.SelfReportClient{Client: client}
// 每日一报
_, err = srclient.Report(cntime.NowCN())
if err != nil {
log.Printf("学号%v 每日一报错误", user.Name)
log.Println(err)
}
if user.TmrOutReport {
log.Printf("离校申请ON")
// 离校申请
tmrlient := &tmrreport.TmrOutClient{Client: client}
err = tmrlient.ReportTmrOut(user.ChuXiaoReason, user.AddressQu, user.AddressDetails)
if err != nil {
log.Printf("学号%v 离校申请错误", user.Name)
log.Println(err)
}
} else {
log.Printf("离校申请OFF")
}
}
c := make(chan []byte)
go func(c chan []byte) {
b := make([]byte, 1)
fmt.Println("输入回车键后退出")
os.Stdin.Read(b)
c <- b
}(c)
<-c
}