Skip to content

Commit

Permalink
feat: add get cultivate plan
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasyRL committed Jan 9, 2025
1 parent 7300cd1 commit 37da0bf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
GPAQueryURL = "https://jwcjwxt2.fzu.edu.cn:81/student/xyzk/jdpm/GPA_sheet.aspx"
VerifyCodeURL = "https://jwcjwxt1.fzu.edu.cn/plus/verifycode.asp"
ExamRoomQueryURL = "https://jwcjwxt2.fzu.edu.cn:81/student/xkjg/examination/exam_list.aspx"
CultivatePlanURL = "https://jwcjwxt2.fzu.edu.cn:81/pyfa/pyjh/pyjh_list.aspx"

JwchPrefix = "https://jwcjwxt2.fzu.edu.cn:81"
JwchReferer = "https://jwcjwxt1.fzu.edu.cn/"
Expand Down
7 changes: 7 additions & 0 deletions jwch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,10 @@ func TestGetExamRoomInfo(t *testing.T) {
t.Error(err)
}
}

func TestGetCultivatePlan(t *testing.T) {
_, err := stu.GetCultivatePlan()
if err != nil {
t.Error(err)
}
}
45 changes: 45 additions & 0 deletions plan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package jwch

import (
"fmt"
"strings"

"github.com/antchfx/htmlquery"

"github.com/west2-online/jwch/constants"
)

func (s *Student) GetCultivatePlan() (string, error) {
info, err := s.GetInfo()
if err != nil {
return "", err
}
viewStateMap, err := s.getState(constants.CultivatePlanURL)
if err != nil {
return "", err
}
res, err := s.PostWithIdentifier(constants.CultivatePlanURL,
map[string]string{
"__VIEWSTATE": viewStateMap["VIEWSTATE"],
"__EVENTVALIDATION": viewStateMap["EVENTVALIDATION"],
"ctl00$njdpl": info.Grade, // 年级
// "ctl00$xymcdpl": "010",// 学院名称
"ctl00$dldpl": "<-全部->", // 大类
"ctl00$zymcdpl": "<-全部->", // 专业代码(无法获取)
"ctl00$zylbdpl": "本专业", // 本专业、辅修

Check failure on line 29 in plan.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)
"ctl00$ContentPlaceHolder1$DDL_syxw": "<-全部->",
"ctl00$ContentPlaceHolder1$BT_submit": "确定",
})
if err != nil {
return "", err
}
xpathExpr := strings.Join([]string{"//tr[td[contains(., '", info.Major, "')]]/td/a[contains(@href, 'pyfa')]/@href"}, "")
node := htmlquery.FindOne(res, xpathExpr)
if node == nil {
return "", fmt.Errorf("%s", "cultivate plan not found")
}

url := htmlquery.SelectAttr(node, "href")
formatUrl := constants.JwchPrefix + "/pyfa/pyjh/" + strings.TrimPrefix(strings.TrimSuffix(url, "')"), "javascript:pop1('")
return formatUrl, nil
}

0 comments on commit 37da0bf

Please sign in to comment.