Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
JwchNoticeURLPrefix = "https://jwch.fzu.edu.cn/"
CultivatePlanURL = "https://jwcjwxt2.fzu.edu.cn:81/pyfa/pyjh/pyjh_list.aspx"
JwchLocateDateUrl = "https://jwcjwxt2.fzu.edu.cn:82/week.asp"
LectureURL = "https://jwcjwxt2.fzu.edu.cn:81/student/glbm/lecture/jxjt_cszt.aspx"
JwchPingYiUrl = "student/jscp/TeaList.aspx"

UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
Expand Down
7 changes: 7 additions & 0 deletions jwch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,10 @@ func TestGetLocateDate(t *testing.T) {
}
fmt.Println(utils.PrintStruct(date))
}

func TestGetLectures(t *testing.T) {
_, err := stu.GetLectures()
if err != nil {
t.Error(err)
}
}
72 changes: 72 additions & 0 deletions lecture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
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 (
"strings"
"time"

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

"github.com/antchfx/htmlquery"
)

// GetLectures 获取报名的讲座
func (s *Student) GetLectures() ([]*Lecture, error) {
resp, err := s.GetWithIdentifier(constants.LectureURL)
if err != nil {
return nil, err
}

list := htmlquery.Find(htmlquery.FindOne(resp, `//*[@id="ContentPlaceHolder1_DataList_xxk"]/tbody`), "tr")

// 前三个元素分别为 空行 标题 表头
list = list[3:]

res := make([]*Lecture, 0)

for _, row := range list {
// 跳过空行
if strings.TrimSpace(htmlquery.SelectAttr(row, "style")) == "" {
continue
}

cells := htmlquery.Find(row, "./td")

res = append(res, &Lecture{
Category: htmlquery.InnerText(cells[0]),
IssueNumber: utils.SafeAtoi(htmlquery.InnerText(cells[1])),
Title: htmlquery.InnerText(cells[2]),
Speaker: htmlquery.InnerText(cells[3]),
Timestamp: parseDateTime(htmlquery.InnerText(cells[4])),
Location: htmlquery.InnerText(cells[5]),
AttendanceStatus: htmlquery.InnerText(cells[6]),
})
}

return res, nil
}

func parseDateTime(dateTime string) int64 {
loc, _ := time.LoadLocation("Asia/Shanghai")
t, err := time.ParseInLocation("2006-01-02\u00A0\u00A015:04", dateTime, loc)
if err != nil {
return 0
}
return t.UnixMilli()
}
11 changes: 11 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ type LocateDate struct {
Term string
}

// Lecture 讲座信息
type Lecture struct {
Category string `json:"category"` // 讲座类别
IssueNumber int `json:"issue_number"` // 期号
Title string `json:"title"` // 讲座题目
Speaker string `json:"speaker"` // 主讲人
Timestamp int64 `json:"timestamp"` // 时间戳
Location string `json:"location"` // 地点
AttendanceStatus string `json:"attendance_status"` // 听取讲座情况
}

// ProxyConfig 青果网络代理配置
type ProxyConfig struct {
AuthKey string `json:"auth_key"` // 青果网络认证密钥
Expand Down