diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-02-09 14:34:45 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-02-09 14:34:45 +0100 |
commit | 8d5bccc8984618c9282e9592882835819306fa07 (patch) | |
tree | 173a9e1c0317a1dce656afaef9979b18cef75c2b /src/server/lib | |
parent | 3989338f0fc2bd394716b4199192b869b8e9bf3b (diff) |
Send basis schedule week to client
Diffstat (limited to 'src/server/lib')
-rw-r--r-- | src/server/lib/getMeetingpointData.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/server/lib/getMeetingpointData.js b/src/server/lib/getMeetingpointData.js index b2225f4..0272398 100644 --- a/src/server/lib/getMeetingpointData.js +++ b/src/server/lib/getMeetingpointData.js @@ -1,5 +1,3 @@ - - const Promise = require('bluebird'); const cheerio = require('cheerio'); const _ = require('lodash'); @@ -41,22 +39,34 @@ function getUsers(page) { return _.flatten([classes, teachers, rooms, students]); } -function getValidWeekNumbers(page) { +function getWeeks(page) { const weekSelector = page('select[name="week"]'); - const weekNumbers = _.map(weekSelector.children(), option => parseInt(option.attribs.value, 10)); + const weeks = _.map(weekSelector.children(), option => ({ + id: cheerio(option).attr('value'), + text: cheerio(option).text(), + })); - return weekNumbers; + return weeks; } function requestData() { lastUpdate = new Date(); - return request('http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm', { timeout: 5000 }).then((response) => { - const page = cheerio.load(response.body); - const users = getUsers(page); - const validWeekNumbers = getValidWeekNumbers(page); + const requests = [ + request('http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm', { timeout: 5000 }), + request('http://www.meetingpointmco.nl/Roosters-AL/doc/basisroosters/frames/navbar.htm', { timeout: 5000 }), + ]; + + return Promise.all(requests).then(([dailyScheduleResponse, basisScheduleResponse]) => { + const dailySchedulePage = cheerio.load(dailyScheduleResponse.body); + const basisSchedulePage = cheerio.load(basisScheduleResponse.body); + const users = getUsers(dailySchedulePage); + const dailyScheduleWeeks = getWeeks(dailySchedulePage); + const basisScheduleWeeks = getWeeks(basisSchedulePage); + + meetingpointData = { users, dailyScheduleWeeks, basisScheduleWeeks }; - meetingpointData = { users, validWeekNumbers }; + console.log(meetingpointData); return meetingpointData; }); |