Skip to content

Commit

Permalink
Merge pull request #12 from jiuxia211/main
Browse files Browse the repository at this point in the history
feat: add get unified exam
  • Loading branch information
jiuxia211 authored Oct 19, 2024
2 parents abc99b9 + 298ca8c commit 07665d6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
CourseURL = "https://jwcjwxt2.fzu.edu.cn:81/student/xkjg/wdxk/xkjg_list.aspx"
MarksQueryURL = "https://jwcjwxt2.fzu.edu.cn:81/student/xyzk/cjyl/score_sheet.aspx"
CETQueryURL = "https://jwcjwxt2.fzu.edu.cn:81/student/glbm/cet/cet_cszt.aspx"
JSQueryURL = "https://jwcjwxt2.fzu.edu.cn:81/student/glbm/computer/jsj_cszt.aspx"
UserInfoURL = "https://jwcjwxt2.fzu.edu.cn:81/jcxx/xsxx/StudentInformation.aspx"
SSOLoginURL = "https://jwcjwxt2.fzu.edu.cn/Sfrz/SSOLogin"
SchoolCalendarURL = "https://jwcjwxt2.fzu.edu.cn:82/xl.asp"
Expand Down
9 changes: 5 additions & 4 deletions credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/west2-online/jwch/constants"
)

func (s *Student) GetCredit() (creditStatistics []CreditStatistics, err error) {
func (s *Student) GetCredit() (creditStatistics []*CreditStatistics, err error) {

resp, err := s.GetWithIdentifier(constants.CreditQueryURL)
if err != nil {
Expand All @@ -26,7 +26,7 @@ func (s *Student) GetCredit() (creditStatistics []CreditStatistics, err error) {
}
tables = tables[:len(tables)-1] // 去掉最后一个表格

creditStatistics = []CreditStatistics{}
creditStatistics = make([]*CreditStatistics, 0)

for _, table := range tables {
rows := htmlquery.Find(table, "//tr")
Expand All @@ -52,7 +52,7 @@ func (s *Student) GetCredit() (creditStatistics []CreditStatistics, err error) {
for i := 0; i < len(temp[0]); i++ {
// 去掉个人信息的列(这列第一个单元格式空的)和“修习情况”这个无效的列
if strings.TrimSpace(temp[0][i]) != "" && !strings.Contains(temp[0][i], "情况") {
bean := CreditStatistics{
bean := &CreditStatistics{
Type: temp[0][i],
Gain: temp[2][i],
Total: temp[1][i],
Expand All @@ -64,7 +64,8 @@ func (s *Student) GetCredit() (creditStatistics []CreditStatistics, err error) {

return creditStatistics, nil
}
func (s *Student) GetGPA() (gpa GPABean, err error) {
func (s *Student) GetGPA() (gpa *GPABean, err error) {
gpa = &GPABean{}
resp, err := s.GetWithIdentifier(constants.GPAQueryURL)
if err != nil {
return gpa, err
Expand Down
22 changes: 22 additions & 0 deletions jwch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,25 @@ func Test_GetGPA(t *testing.T) {

fmt.Println(utils.PrintStruct(gpa))
}

func TestGetUnifiedExam(t *testing.T) {
if !islogin {
err := login()
if err != nil {
t.Error(err)
}
}
cet, err := stu.GetCET()
if err != nil {
t.Error(err)
}

fmt.Println(utils.PrintStruct(cet))

js, err := stu.GetJS()
if err != nil {
t.Error(err)
}

fmt.Println(utils.PrintStruct(js))
}
53 changes: 49 additions & 4 deletions mark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/west2-online/jwch/constants"
"github.com/west2-online/jwch/errno"
"github.com/west2-online/jwch/utils"
"golang.org/x/net/html"

"github.com/antchfx/htmlquery"
)
Expand Down Expand Up @@ -61,13 +62,57 @@ func (s *Student) GetMarks() (resp []*Mark, err error) {
}

// 获取CET成绩
func (s *Student) GetCET() error {
func (s *Student) GetCET() ([]*UnifiedExam, error) {
resp, err := s.GetWithIdentifier(constants.CETQueryURL)
if err != nil {
return nil, err
}

return s.parseUnifiedExam(resp)
}

// 获取省计算机成绩
func (s *Student) GetJS() ([]*UnifiedExam, error) {
resp, err := s.GetWithIdentifier(constants.JSQueryURL)
if err != nil {
return err
return nil, err
}

return s.parseUnifiedExam(resp)
}

// 解析统一考试成绩
func (s *Student) parseUnifiedExam(resp *html.Node) ([]*UnifiedExam, error) {
var exams []*UnifiedExam

// 查找包含成绩的表格
table := htmlquery.FindOne(resp, `//*[@id="ContentPlaceHolder1_DataList_xxk"]`)
if table == nil {
return nil, fmt.Errorf("failed to find the exam table")
}

// 查找所有考试成绩行
rows := htmlquery.Find(table, `.//tr[@onmouseover]`)
if len(rows) == 0 {
return nil, nil // 这里不返回错误,因为有可能没有考试成绩
}

// 遍历每一行,提取成绩信息
for _, row := range rows {
tds := htmlquery.Find(row, `.//td`)
if len(tds) < 3 {
continue // 如果某行的列数不满足要求则跳过
}

// 创建一个新的 UnifiedExam 对象
exam := &UnifiedExam{
Name: htmlquery.InnerText(tds[0]),
Score: htmlquery.InnerText(tds[2]),
Term: htmlquery.InnerText(tds[1]),
}

exams = append(exams, exam)
}

fmt.Println(resp)
return nil
return exams, nil
}
6 changes: 6 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ type GPABean struct {
Time string // 绩点计算时间
Data []GPAData
}

type UnifiedExam struct {
Name string
Score string
Term string
}

0 comments on commit 07665d6

Please sign in to comment.