main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/tebeka/selenium"
  5. "io/ioutil"
  6. "os"
  7. "ouch/student"
  8. "sync"
  9. )
  10. func handleCount(accounts [][]string) {
  11. var wg sync.WaitGroup
  12. serviceArray := []*selenium.Service{}
  13. wds := []selenium.WebDriver{}
  14. for _, v := range accounts {
  15. fmt.Printf("账号:%v\n", v)
  16. //err := student.StartOneStudent("2051101453478", "Ouchn19991209", "李丰")
  17. wg.Add(1)
  18. go func(name string, pass string, real string) {
  19. // 开始执行
  20. service, wd, err := student.StartOneStudent(name, pass, real)
  21. if service != nil {
  22. serviceArray = append(serviceArray, service)
  23. }
  24. if wd != nil {
  25. wds = append(wds, wd)
  26. }
  27. if err != nil {
  28. fmt.Printf("%s %v \n", v[2], err)
  29. }
  30. wg.Done()
  31. }(v[0], v[1], v[2])
  32. //time.Sleep(20*time.Second)
  33. }
  34. wg.Wait()
  35. for _, v := range wds {
  36. v.Quit()
  37. }
  38. for _, v := range serviceArray {
  39. v.Stop()
  40. }
  41. }
  42. func main() {
  43. // 取账号
  44. accounts, _ := student.GetAcounts("account.txt")
  45. fmt.Printf("accounts:%v\n", len(accounts))
  46. for _, v := range accounts {
  47. if len(v) != 3 {
  48. fmt.Printf("账号不完整\n")
  49. return
  50. }
  51. }
  52. start := 0
  53. end := 1
  54. for {
  55. if end > len(accounts) {
  56. end = len(accounts)
  57. }
  58. if start >= end {
  59. break
  60. }
  61. // 处理账号
  62. handleCount(accounts[start:end])
  63. // 记录执行过的账号
  64. str := fmt.Sprintf("start:%d,%s,%s,%s end:%d,%s,%s,%s\r\n",
  65. start, accounts[start][0], accounts[start][1], accounts[start][2],
  66. end, accounts[end-1][0], accounts[end-1][1], accounts[end-1][2],)
  67. os.Remove("record.txt")
  68. ioutil.WriteFile("record.txt", []byte(str), 0666)
  69. //fmt.Printf("finish one\n")
  70. //time.Sleep(1000*time.Second)
  71. start = end
  72. end = end + 1
  73. }
  74. fmt.Printf("over\n")
  75. //time.Sleep(100*time.Second)
  76. }