-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
103 lines (82 loc) · 1.99 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
package main
import (
"os"
"sync"
"time"
"github.com/sirupsen/logrus"
)
func init() {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
logrus.SetOutput(os.Stdout)
}
func main() {
options := RunCLI()
credentials := &Credentials{
ID: options.ID,
Password: options.Password,
}
goer := NewGoer(options.Origin, NewGoerClient())
logrus.Warn("=======================================================")
logrus.Warn("DO NOT ACCESS YOUR ACCOUNT WHEN THIS TOOL IS RUNNING!!!")
logrus.Warn("=======================================================")
// Try to log in again until the registration is ready
for {
if ok := goer.Login(credentials); ok {
// goer.Greet()
if isOpen := goer.IsRegistrationOpen(); isOpen {
break
} else {
goer.Clear()
}
}
time.Sleep(1 * time.Second)
logrus.Info("Login again...")
}
// Start registration
var wg sync.WaitGroup
var mu sync.Mutex
courseCounter := 0
courseIDChannel := make(chan string, options.Workers)
go func() {
for _, courseID := range options.CourseIDs {
courseIDChannel <- courseID
}
}()
for i := 0; i < int(options.Workers); i++ {
wg.Add(1)
go func() {
for courseID := range courseIDChannel {
if ok := goer.RegisterCourse(courseID); !ok {
courseIDChannel <- courseID
} else {
// Save the enrolled course after successful registration
if options.CarefulMode {
goer.SaveRegistration()
}
// Put the course ID back if spam is enable
if options.SpamInterval != 0 {
courseIDChannel <- courseID
time.Sleep(time.Duration(options.SpamInterval) * time.Second)
} else {
mu.Lock()
courseCounter++
// Close the channel if all courses are registered
if courseCounter == len(options.CourseIDs) {
close(courseIDChannel)
}
mu.Unlock()
}
}
}
wg.Done()
}()
}
wg.Wait()
// Save all registered courses
if !options.CarefulMode {
goer.SaveRegistration()
}
logrus.Info("Done!")
}