-
Notifications
You must be signed in to change notification settings - Fork 2
/
test2.ts
54 lines (44 loc) · 1.62 KB
/
test2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ical, { VEvent } from "node-ical"
import { DateTime } from "luxon"
import { arrify } from "./lib/util"
const icalURL = "C:/Users/hamza/Downloads/Fall 2023 - Chicago.ics"
const events = ical.sync.parseFile(icalURL)
/*
[x] - Get timing data from the event
[x] - Create slash command
[x] - Get attachemnt info
[x] - Parse info
[] - Send to mongodb
[] - Update schema
[] - Utility commands (remove, update, view, see others)
[] - Some sort of viewer using canvas
*/
// TODO - Figure what saturday and sunday are
const dayMapping = {
"MO": "M",
"TU": "T",
"WE": "W",
"TH": "R",
"FR": "F",
"SA": "R",
"SU": "N"
}
const parseClass = (event: ical.VEvent) => {
if(!("summary" in event))
return
const summaryPartial = event.summary.slice(0, -2).split(" ")
const courseName = summaryPartial.slice(0, -2).join(" ")
const courseID = summaryPartial.slice(-2).join(" ")
const [crn, creditHours, level, instructor] = event.description.split("\n").map(_ => _.split(": ")[1]?.trim())
const [startTime, endTime] = [event.start, event.end].map(_ => DateTime.fromJSDate(_ as Date, {zone: "America/Chicago"}).toFormat("hh:mm a"))
const { dtstart, until, byweekday } = event.rrule.origOptions
const [startDate, endDate] = [dtstart, until].map(_ => DateTime.fromJSDate(_ as Date, {zone: "America/Chicago"}).toFormat("MM/dd/yyyy"))
const days = arrify(byweekday).map(_ => dayMapping[_.toString()])
const res = {
courseName, courseID, crn, creditHours, level, instructor, startTime, endTime, startDate, endDate, days
}
console.log(res)
}
for (const event of Object.values(events)) {
parseClass(event as VEvent)
};