diff --git a/api.js b/api.js index 67579c7..0554801 100644 --- a/api.js +++ b/api.js @@ -13,7 +13,6 @@ const $ = require('cheerio'); var moment = require('moment'); module.exports = { - sis: { fetch: (url, next) => { request.get("http://sis.rpi.edu/" + url, (err,res,body) => { @@ -126,6 +125,12 @@ module.exports = { } }); }, + get_weekly_schedule: (next) => { + + }, + get_today_schedule: (next) => { + request(sources.sis.schedule) + }, get_student_info: (next) => { request.post() }, @@ -136,7 +141,7 @@ module.exports = { request.get(sources.sis.holds, (err, res, html) => { if (err) next(err); else { - if ($('body > div.pagebodydiv > table.datadisplaytable > tbody > tr:nth-child(2) > td:nth-child(1)').html()!='') + if ($('div.pagebodydiv > table.datadisplaytable > tbody > tr:nth-child(2)', html).html()!=null) next(null, true); else next(null, false); } diff --git a/routes/sis.js b/routes/sis.js index d53a840..c528fe6 100644 --- a/routes/sis.js +++ b/routes/sis.js @@ -29,6 +29,10 @@ module.exports = function(app, api, auth) { }) ); + app.get("/schedule/today", (req,res) => { + + }); + // Logout route app.get("/logout", (req,res) =>{ api.logout( (err) => { -- 2.51.2 From 213a891b4897f6c98e09c3a6a2b0939a8eb4be8a Mon Sep 17 00:00:00 2001 From: Chris Vanderloo Date: Thu, 21 Mar 2019 22:00:10 -0400 Subject: [PATCH 2/5] Implemented schedule parsing and inputting for the week --- api.js | 42 ++++++++++++++++++++++++++++++++++++++---- routes/sis.js | 12 +++++++++--- sources.json | 5 ++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/api.js b/api.js index 0554801..3459917 100644 --- a/api.js +++ b/api.js @@ -125,11 +125,45 @@ module.exports = { } }); }, - get_weekly_schedule: (next) => { + get_schedule: (next) => { + request(sources.sis.schedule.current_week, (err, res, html) => { + if (err) next(err); + else { + var schedule_date = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; + // ordered by day of the week + var obj = { + 'start': '', + 'end': '', + 'clinfo': [[],[],[],[],[]] + }; + $('div.pagebodydiv > table.datadisplaytable > tbody tr', html).each((i, row) => { + $('td', row).each((j, td) => { + var classinfo = $('a', td).html(); + if (classinfo) { + var m_f = 'h:mm a'; + var clinfo = classinfo.split('
'); + var start_time = moment(clinfo[2].split('-')[0], m_f); + var end_time = moment(clinfo[2].split('-')[1], m_f); - }, - get_today_schedule: (next) => { - request(sources.sis.schedule) + if (obj.start==='') obj.start = start_time.format(m_f); + else if (moment(obj.start, m_f).isAfter(start_time)) obj.start = start_time.format(m_f); + + if (obj.end==='') obj.end = end_time.format(m_f); + else if (moment(obj.end, m_f).isBefore(end_time)) obj.end = end_time.format(m_f); + + obj.clinfo[j].push({ + "name": clinfo[0], + "CRN": clinfo[1].split(' ')[0], + "start_time": start_time.format(m_f), + "end_time": end_time.format(m_f), + "location": clinfo[3] + }); + } + }); + }); + next(null, JSON.stringify(obj)); + } + }); }, get_student_info: (next) => { request.post() diff --git a/routes/sis.js b/routes/sis.js index c528fe6..24b66a3 100644 --- a/routes/sis.js +++ b/routes/sis.js @@ -1,4 +1,3 @@ - module.exports = function(app, api, auth) { app.get("/fetch", (req,res) => { @@ -29,8 +28,15 @@ module.exports = function(app, api, auth) { }) ); - app.get("/schedule/today", (req,res) => { - + app.get("/schedule", (req,res) => { + api.get_schedule((err, body) => { + if (!err) + res.send(body); + else { + res.statusMessage = err; + res.status(500).send(err); + } + }) }); // Logout route diff --git a/sources.json b/sources.json index d5709e7..0be9811 100644 --- a/sources.json +++ b/sources.json @@ -6,7 +6,10 @@ "get_student_menu": "https://sis.rpi.edu/rss/twbkwbis.P_GenMenu?name=bmenu.P_StuMainMnu", "address": "https://sis.rpi.edu/rss/bwgkogad.P_SelectAtypUpdate", "registration": "https://sis.rpi.edu/rss/bwskrsta.P_RegsStatusDisp", - "holds": "https://sis.rpi.edu/rss/bwskoacc.P_ViewHold" + "holds": "https://sis.rpi.edu/rss/bwskoacc.P_ViewHold", + "schedule": { + "current_week": "https://sis.rpi.edu/rss/bwskfshd.P_CrseSchd" + } }, "yacs": { "departments": "https://yacs.cs.rpi.edu/api/v5/schools.json?show_departments=true", -- 2.51.2 From 7fab1e685f103641995b8b17c1e86a3a23dfe2ff Mon Sep 17 00:00:00 2001 From: Chris Vanderloo Date: Fri, 22 Mar 2019 14:36:10 -0400 Subject: [PATCH 3/5] Corrected today information --- api.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api.js b/api.js index 3459917..5755feb 100644 --- a/api.js +++ b/api.js @@ -134,6 +134,7 @@ module.exports = { var obj = { 'start': '', 'end': '', + 'today': [], 'clinfo': [[],[],[],[],[]] }; $('div.pagebodydiv > table.datadisplaytable > tbody tr', html).each((i, row) => { @@ -150,14 +151,18 @@ module.exports = { if (obj.end==='') obj.end = end_time.format(m_f); else if (moment(obj.end, m_f).isBefore(end_time)) obj.end = end_time.format(m_f); - - obj.clinfo[j].push({ + + var classinfo = { "name": clinfo[0], "CRN": clinfo[1].split(' ')[0], "start_time": start_time.format(m_f), "end_time": end_time.format(m_f), "location": clinfo[3] - }); + } + + obj.clinfo[j].push(classinfo); + if (moment().day()-1 == j) + obj.today.push(classinfo); } }); }); -- 2.51.2 From 1c1e6388b432712b9aeac6fd976eca2c29bd1756 Mon Sep 17 00:00:00 2001 From: Chris Vanderloo Date: Fri, 22 Mar 2019 15:18:18 -0400 Subject: [PATCH 4/5] Adds basic class info management --- api.js | 8 ++++++++ routes/sis.js | 11 +++++++++++ sources.json | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api.js b/api.js index 5755feb..123955c 100644 --- a/api.js +++ b/api.js @@ -170,6 +170,14 @@ module.exports = { } }); }, + get_class_info: (crn, next) => { + request(sources.sis.schedule.class_info + crn, (err, res, html) => { + if (err) next(err); + else { + next(null, html); + } + }); + }, get_student_info: (next) => { request.post() }, diff --git a/routes/sis.js b/routes/sis.js index 24b66a3..5b1705f 100644 --- a/routes/sis.js +++ b/routes/sis.js @@ -39,6 +39,17 @@ module.exports = function(app, api, auth) { }) }); + app.get("/class_info", (req,res) => { + api.get_class_info(req.query.crn, (err, body) => { + if (!err) + res.send(body); + else { + res.statusMessage = err; + res.status(500).send(err); + } + }); + }); + // Logout route app.get("/logout", (req,res) =>{ api.logout( (err) => { diff --git a/sources.json b/sources.json index 0be9811..1fc3232 100644 --- a/sources.json +++ b/sources.json @@ -8,7 +8,8 @@ "registration": "https://sis.rpi.edu/rss/bwskrsta.P_RegsStatusDisp", "holds": "https://sis.rpi.edu/rss/bwskoacc.P_ViewHold", "schedule": { - "current_week": "https://sis.rpi.edu/rss/bwskfshd.P_CrseSchd" + "current_week": "https://sis.rpi.edu/rss/bwskfshd.P_CrseSchd", + "class_info": "https://sis.rpi.edu/rss/bwskfshd.P_CrseSchdDetl?crn=" } }, "yacs": { -- 2.51.2 From ee872c0e6264968ea1cf235d27ed98c6e01983cf Mon Sep 17 00:00:00 2001 From: Chris Vanderloo Date: Fri, 22 Mar 2019 17:11:53 -0400 Subject: [PATCH 5/5] Wrote and corrected getNextTerm and getCurrentTerm, set up getClassInfo --- api.js | 31 +++++++++++++++++++++++++++---- routes/sis.js | 20 +++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/api.js b/api.js index 123955c..9b0c0a2 100644 --- a/api.js +++ b/api.js @@ -75,6 +75,16 @@ module.exports = { }); }, get_current_term: (next) => { + request.get(sources.sis.schedule.current_week, (err, res, html) => { + if (!err) { + //success! + var reply = $('input[name="termDir"]', html).attr('value'); + next(null, reply); + } + else next(err); + }); + }, + get_next_term: (next) => { request.get(sources.sis.classes, (err, res, html) => { if (!err) { //success! @@ -112,7 +122,13 @@ module.exports = { if (err) next(err); else { var obj = {}; - var arr = $('div.pagebodydiv > table:nth-child(2) > tbody > tr:nth-child(2)', html).html().split('\n'); + try { + var arr = $('div.pagebodydiv > table:nth-child(2) > tbody > tr:nth-child(2)', html).html().split('\n'); + } + catch (err) { + next(err); + return; + } var start = moment($('td', arr[1]).text() + " " + $('td', arr[2]).text(), "MMM D, YYYY hh:mm a"); var end = moment($('td', arr[3]).text() + " " + $('td', arr[4]).text(), "MMM D, YYYY hh:mm a"); obj["start_date"] = start.format("MMMM Do"); @@ -170,11 +186,18 @@ module.exports = { } }); }, - get_class_info: (crn, next) => { - request(sources.sis.schedule.class_info + crn, (err, res, html) => { + get_class_info: (crn, term, next) => { + request(sources.sis.schedule.class_info + crn + "&term_in=" + term, (err, res, html) => { if (err) next(err); else { - next(null, html); + var obj = {}; + var split_info = $('div.pagebodydiv > table > caption', html).html().split(' - '); + obj["name"] = split_info[0]; + obj["id"] = split_info[1]; + obj["section"] = split_info[2]; + obj["instructor"] = $('body > div.pagebodydiv > table:nth-child(3) > tbody > tr:nth-child(4) > td', html).text() + obj["instructor_email"] = $('body > div.pagebodydiv > table:nth-child(3) > tbody > tr:nth-child(4) > td > a', html).attr('href') + next(null, obj); } }); }, diff --git a/routes/sis.js b/routes/sis.js index 5b1705f..e25f8df 100644 --- a/routes/sis.js +++ b/routes/sis.js @@ -13,11 +13,11 @@ module.exports = function(app, api, auth) { api.login(req.query.user, req.query.pass, (err, cookie, name) => { if (!err) { if (cookie[0].startsWith("SESSID=;")) res.status(403).send("No SESSID returned"); - else api.get_current_term((err, term) => { + else api.get_next_term((err, term) => { var reply = new Object(); - reply.term = term; reply.sessid = cookie[0].replace("SESSID=", ""); reply.name = name; + reply.term = term; res.send(JSON.stringify(reply)); }); } @@ -40,13 +40,15 @@ module.exports = function(app, api, auth) { }); app.get("/class_info", (req,res) => { - api.get_class_info(req.query.crn, (err, body) => { - if (!err) - res.send(body); - else { - res.statusMessage = err; - res.status(500).send(err); - } + api.get_current_term((err, term) => { + api.get_class_info(req.query.crn, term, (err, body) => { + if (!err) + res.send(body); + else { + res.statusMessage = err; + res.status(500).send(err); + } + }); }); });