-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
43 lines (40 loc) · 1.01 KB
/
parser.js
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
function scheduleHtmlParser(json_str) {
courses_json = JSON.parse(json_str)
const courseInfos = []
for (course of courses_json) {
const name = course.kcmc
const position = course.cdmc
const teacher = course.xm
const weeksTemp = course.zcd.replace('周', '').split(',')
const weeks = []
weeksTemp.forEach(w => {
w = w.split('-')
if (w.length === 1) {
weeks.push(parseInt(w))
} else {
for (let i = parseInt(w[0]); i <= parseInt(w[1]); i += 1) {
weeks.push(i)
}
}
})
const day = parseInt(course.xqj)
const sectionsTemp = course.jcor.split('-')
const sections = []
if (sectionsTemp.length == 1) {
sections.push(parseInt(sectionsTemp[0]))
} else {
for (let i = parseInt(sectionsTemp[0]); i <= parseInt(sectionsTemp[1]); i += 1) {
sections.push(i)
}
}
courseInfos.push({
name,
teacher,
position,
weeks,
day,
sections,
})
}
return courseInfos
}