Skip to content

Instantly share code, notes, and snippets.

@xfoxfu
Created March 4, 2021 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xfoxfu/2931668ccde85b35bf9c5239bbf33c0e to your computer and use it in GitHub Desktop.
Save xfoxfu/2931668ccde85b35bf9c5239bbf33c0e to your computer and use it in GitHub Desktop.
SYSU Classtable to ics 中山大学教务系统课程表导出ics
const ics = require("ics");
import * as moment from "moment";
// response of https://jwxt.sysu.edu.cn/jwxt/schedule/agg/stuTimeTabPrint/studentQuery
// export const data = {}; // data;
import { data } from "./data";
export const weekday = {
"1": "MO",
"2": "TU",
"3": "WE",
"4": "TH",
"5": "FR",
"6": "SA",
"7": "SU",
};
export const times = {
1: ["08:00", "08:45"],
2: ["08:55", "09:40"],
3: ["10:00", "10:45"],
4: ["10:55", "11:40"],
5: ["14:20", "15:05"],
6: ["15:15", "16:00"],
7: ["16:20", "17:05"],
8: ["17:15", "18:00"],
9: ["19:00", "19:45"],
10: ["19:55", "20:40"],
11: ["20:50", "21:35"],
};
const events = Object.values(data.data.timetable)
.filter((v) => v !== null)
.reduce((pv, cv) => pv.concat(cv), [])
// .filter((v) => v.courseName.includes("数字图像处理"))
.map((v) => {
console.error(v.startWeek, v.endWeek);
return v;
})
// .filter((v) => v.startWeek > 10)
.map((val) => {
const st = moment(`2021-02-21 ${times[val.startClassTimes][0]}`)
.utcOffset("+08:00")
.add(val.startWeek - 1, "weeks")
.add(parseInt(val.week), "days");
const end = moment(`2021-02-21 ${times[val.endClassTimes][1]}`)
.utcOffset("+08:00")
.add(val.startWeek - 1, "weeks")
.add(parseInt(val.week), "days");
const finishWeek = moment("2021-02-21 00:00")
.add(val.startWeek - 1, "weeks")
.add(9, "weeks")
.utcOffset("+08:00")
// .utc()
.format("YYYYMMDDTHHmmss\\Z");
return {
start: [
st.year(),
st.month() + 1,
st.date(),
st.hour(),
st.minute(),
st.second(),
],
startOutputType: "local",
endOutputType: "local",
end: [
end.year(),
end.month() + 1,
end.date(),
end.hour(),
end.minute(),
end.second(),
],
title: val.courseName.split(")")[1].replace("/", ""),
description: [
val.timeDetail,
val.courseName,
val.teachingStaffName,
val.classPlace,
val.chooseSumNum,
].join(""),
location: val.classPlace
.split("-")[2]
.split("(")[0]
.replace("东校实验中心", "实"),
recurrenceRule: `FREQ=WEEKLY;BYDAY=${
weekday[val.week]
};INTERVAL=1;UNTIL=${finishWeek}`,
};
});
// console.log(events[0]);
const { error, value } = ics.createEvents(events);
if (error) {
console.log(error);
}
console.log(value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment