From b49fc76f97c4c7c191ba593d1ce503ca24492d1b Mon Sep 17 00:00:00 2001 From: FanR <103872180+FantasyRL@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:34:10 +0800 Subject: [PATCH] feat: add get cultivate plan (#20) * feat: add get cultivate plan * feat: CI --- constants/constants.go | 1 + jwch_test.go | 7 +++++ plan.go | 61 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 plan.go diff --git a/constants/constants.go b/constants/constants.go index 45f1c57..4f6dc8b 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -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/" diff --git a/jwch_test.go b/jwch_test.go index c73872a..5751c8e 100644 --- a/jwch_test.go +++ b/jwch_test.go @@ -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) + } +} diff --git a/plan.go b/plan.go new file mode 100644 index 0000000..fc02900 --- /dev/null +++ b/plan.go @@ -0,0 +1,61 @@ +/* +Copyright 2024 The west2-online Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +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": "本专业", // 本专业、辅修 + "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 +}