Skip to content

Commit

Permalink
feat: 改变抢课时检索按开课计划选课班号的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafYeeXYZ committed Dec 25, 2024
1 parent 56bcca0 commit 5735acc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
92 changes: 69 additions & 23 deletions catch.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,42 +388,36 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours
iiframe := page.Frames()[2]
iiiframe := iiframe.FrameLocator("#frmReport")

// 输入班号
ele = iiframe.Locator("#txt_skbjdm")
err = ele.Fill(classID)
if err != nil { errCh <- err; return }

// 点击 "检索"
ele = iiframe.Locator("#btnQry")
err = ele.Click()
if err != nil { errCh <- err; return }
// ------ 2024.12.25 ------
// 不再通过输入班号来检索课程, 而是直接依次检索 DOM
// ------------------------

// 等待加载
iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{
State: playwright.LoadStateNetworkidle,
})
time.Sleep(time.Duration(speed) * time.Millisecond)

// 可选人数
ele = iiiframe.Locator("#tr0_kxrs")

// 检索课程
eleIndex := 0
count = 0
for {
if count > 15000 {
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID))
// runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出
errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID)
return
}
// 班号
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_curent_skbjdm", eleIndex))
if exists, _ := ele.IsVisible(); exists {
// 检查是否可选人数为 0
// 如果不是给定的班号, 则继续检索
if text, _ := ele.InnerText(); text != classID {
eleIndex++
continue
}
// 如果是给定的班号, 则检查是否可选人数为 0
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_kxrs", eleIndex))
if text, _ := ele.InnerText(); text == "0" {
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID))
// runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出
errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID)
return
} else {
// 勾选
ele = iiiframe.Locator("#tr0_ischk input")
// 勾选
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_ischk input", eleIndex))
err = ele.Click()
if err != nil { errCh <- err; return }
break
Expand All @@ -432,9 +426,61 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID))
time.Sleep(time.Duration(speed) * time.Millisecond)
count += speed
if count > 15000 {
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时", courseID))
errCh <- fmt.Errorf("课程 %s 网络超时", courseID)
return
}
}
}

// // 输入班号
// ele = iiframe.Locator("#txt_skbjdm")
// err = ele.Fill(classID)
// if err != nil { errCh <- err; return }

// // 点击 "检索"
// ele = iiframe.Locator("#btnQry")
// err = ele.Click()
// if err != nil { errCh <- err; return }

// // 等待加载
// iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{
// State: playwright.LoadStateNetworkidle,
// })
// time.Sleep(time.Duration(speed) * time.Millisecond)

// // 可选人数
// ele = iiiframe.Locator("#tr0_kxrs")
// count = 0
// for {
// if count > 15000 {
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID))
// // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出
// errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID)
// return
// }
// if exists, _ := ele.IsVisible(); exists {
// // 检查是否可选人数为 0
// if text, _ := ele.InnerText(); text == "0" {
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID))
// // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出
// errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID)
// return
// } else {
// // 勾选
// ele = iiiframe.Locator("#tr0_ischk input")
// err = ele.Click()
// if err != nil { errCh <- err; return }
// break
// }
// } else {
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID))
// time.Sleep(time.Duration(speed) * time.Millisecond)
// count += speed
// }
// }

// 点击 "确定"
ele = iiframe.Locator("#btnSubmit")
err = ele.Click()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function Header() {
className='w-full h-full flex items-center justify-start text-sm gap-2 pl-3'
>
<span className='font-bold' data-tg-tour='测试'>小鸦抢课</span>
<Tag id='version' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>2.0.3</Tag>
<Tag id='version' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>2.1.0</Tag>
<Tag id='status' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>{systemStatus}</Tag>
</p>
<button
Expand Down

0 comments on commit 5735acc

Please sign in to comment.