-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
91 lines (74 loc) · 1.76 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
package main
import (
"fmt"
"goFastForVideo/file"
"goFastForVideo/query"
"goFastForVideo/study"
"math/rand"
"strings"
"sync"
"time"
)
var query_url = "https://plat.xzjxjy.com"
func main() {
var Wg sync.WaitGroup
cons := file.ReadSetting()
for _, con := range cons {
yearArr := strings.Split(con.Years, ",")
myCourses := query.ReadCourses(con.UserName, con.Password, query.GetRes(con.UserName, con.Password, query_url+"/myCourses.asp"))
for k, v := range myCourses {
if in(k.Title, yearArr) {
study.StartStudy(con.UserName, con.Password, v, &Wg)
}
// 考试
}
time.Sleep(time.Duration(con.DoneTIme) * time.Second)
fmt.Println("【", con.UserName, "】学习结束")
}
Wg.Wait()
fmt.Println("学习结束")
}
// 测试进度条
func testProgress() {
// 更新当前的状态
fmt.Println("开始任务... ")
var total = 30
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(400)) * time.Millisecond)
// 计算百分比
percent := int(float32(i+1) * 100.0 / float32(total))
pro := Progress(percent)
pro.Show()
}
fmt.Printf("\nDone!\n")
}
// Progress 进度
type Progress int
// Show 显示进度
func (x Progress) Show() {
percent := int(x)
// fmt.Println("percent: ", percent)
total := 50 // 这个total是格子数
middle := int(percent * total / 100.0)
// fmt.Printf("middle:%d\n", middle)
arr := make([]string, total)
for j := 0; j < total; j++ {
if j < middle-1 {
arr[j] = "-"
} else if j == middle-1 {
arr[j] = ">"
} else {
arr[j] = " "
}
}
bar := fmt.Sprintf("[%s]", strings.Join(arr, ""))
fmt.Printf("\r%s %%%d", bar, percent)
}
func in(target string, yearArr []string) bool {
for _, year := range yearArr {
if strings.Contains(target, year) {
return true
}
}
return false
}