Created
July 21, 2019 19:59
-
-
Save KYDronePilot/2440bf6d1d23130cb6bebf73f8bf3b87 to your computer and use it in GitHub Desktop.
Get info and schedule for Eastern Kentucky University courses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get all of the raw course tables (info and schedule) | |
let rawTables = document.querySelectorAll("table.datadisplaytable"); | |
// Zip together info and schedule tables of the same course | |
let rawCourses = []; | |
for (let i = 0; i < rawTables.length; i += 2) { | |
let course = {}; | |
course.info = rawTables[i]; | |
course.schedule = rawTables[i + 1]; | |
rawCourses.push(course); | |
} | |
// Get the actual course information | |
let courseData = []; | |
for (let rawCourse of rawCourses) { | |
let course = {}; | |
// Get course name, coded name (e.g. CSC 191), and section | |
let summary = rawCourse.info.querySelector("caption").innerText; | |
[course.name, course.code, course.section] = summary.split(" - "); | |
for (let row of rawCourse.info.querySelectorAll("tbody > tr")) { | |
if (row.querySelector("th").querySelector("acronym") | |
&& row.querySelector("th").querySelector("acronym").innerText === "CRN") | |
course.crn = row.querySelector("td").innerText.trim(); | |
if (row.querySelector("th").innerText === "Assigned Instructor:") | |
course.instructor = row.querySelector("td").innerText.trim(); | |
if (row.querySelector("th").innerText === "Credits:") | |
course.credits = row.querySelector("td").innerText.trim(); | |
} | |
// Get the schedule info | |
let scheduleRows = [...rawCourse.schedule.querySelectorAll("tr")].slice(1); | |
console.log(scheduleRows); | |
let schedules = []; | |
for (let rawSchedule of scheduleRows) { | |
let schedule = {}; | |
let rawScheduleElements = [...rawSchedule.querySelectorAll("td")]; | |
[schedule.startTime, schedule.endTime] = rawScheduleElements[1].innerText.split(" - "); | |
schedule.days = rawScheduleElements[2].innerText; | |
schedule.location = rawScheduleElements[3].innerText; | |
[schedule.startDate, schedule.endDate] = rawScheduleElements[4].innerText.split(" - "); | |
schedules.push(schedule); | |
} | |
course.schedules = schedules; | |
courseData.push(course); | |
} | |
completion(courseData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used for creating a Siri shortcut that will add classes to a calendar