Skip to content

Commit 658b7c8

Browse files
committed
fix: make UID unique, remove TZID (maybe caused by a bad design of go-ical, but I don't know it really)
1 parent 95e3e02 commit 658b7c8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## 使用
99

10-
1. 从release下载编译好的CourseICS或拉去源码自己编译
10+
1. 从release下载编译好的CourseICS或拉取源码自己编译
1111
2. 在命令行(或其他终端)中运行该小工具
1212
3. 交互式输入智慧杭电账号密码
1313
4. 在运行目录下生成文件`course.ics`

main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/teambition/rrule-go"
99
"log"
1010
"os"
11+
"strconv"
1112
"time"
1213
)
1314

@@ -68,10 +69,9 @@ func main() {
6869
event := ical.NewEvent()
6970
event.Props.SetDateTime(ical.PropDateTimeStart, startDay.AddDate(0, 0, (v.StartWeek-1)*7+v.WeekDay-1).Add(hduTimeList[v.StartSection-1]))
7071
event.Props.SetDateTime(ical.PropDateTimeEnd, startDay.AddDate(0, 0, (v.StartWeek-1)*7+v.WeekDay-1).Add(hduTimeList[v.EndSection-1]).Add(time.Minute*45))
71-
event.Props.SetText(ical.PropSummary, fmt.Sprintf("%s %s %s %s", v.CourseName, v.ClassRoom, v.TeacherName, v.CourseSchema))
7272
event.Props.SetDateTime(ical.PropDateTimeStamp, startDay)
73-
// 我不理解,但是不这么做这个go-ical库不让我过编译
74-
event.Props.SetText(ical.PropUID, "")
73+
event.Props.SetText(ical.PropSummary, fmt.Sprintf("%s %s %s %s", v.CourseName, v.ClassRoom, v.TeacherName, v.CourseSchema))
74+
event.Props.SetText(ical.PropUID, v.CourseCode+strconv.Itoa(v.WeekDay)+strconv.Itoa(v.StartWeek))
7575
count := v.EndWeek - v.StartWeek + 1
7676
interval := 1
7777
if v.Period != "" {
@@ -102,7 +102,9 @@ func main() {
102102
log.Fatalln(err)
103103
return
104104
}
105-
if err := os.WriteFile("./course.ics", buf.Bytes(), os.ModePerm); err != nil {
105+
// yysy我不理解, 可能是库的问题
106+
out := bytes.ReplaceAll(buf.Bytes(), []byte(";TZID=Local"), []byte(""))
107+
if err := os.WriteFile("./course.ics", out, os.ModePerm); err != nil {
106108
log.Fatalln(err)
107109
return
108110
}

0 commit comments

Comments
 (0)