diff options
Diffstat (limited to 'src/server/lib/schools')
-rw-r--r-- | src/server/lib/schools/hetmml/axios.js | 11 | ||||
-rw-r--r-- | src/server/lib/schools/hetmml/getScheduleData.js | 20 | ||||
-rw-r--r-- | src/server/lib/schools/hetmml/getURLOfUser.js | 3 |
3 files changed, 20 insertions, 14 deletions
diff --git a/src/server/lib/schools/hetmml/axios.js b/src/server/lib/schools/hetmml/axios.js new file mode 100644 index 0000000..3993890 --- /dev/null +++ b/src/server/lib/schools/hetmml/axios.js @@ -0,0 +1,11 @@ +const axios = require('axios'); +const iconv = require('iconv-lite'); + +const instance = axios.create({ + baseURL: 'http://www.meetingpointmco.nl/Roosters-AL/doc/', + timeout: 5000, + responseType: 'arraybuffer', + transformResponse: [responseBody => iconv.decode(responseBody, 'iso-8859-1')], +}); + +module.exports = instance; diff --git a/src/server/lib/schools/hetmml/getScheduleData.js b/src/server/lib/schools/hetmml/getScheduleData.js index 303af6d..6789479 100644 --- a/src/server/lib/schools/hetmml/getScheduleData.js +++ b/src/server/lib/schools/hetmml/getScheduleData.js @@ -1,11 +1,9 @@ -const Promise = require('bluebird'); const cheerio = require('cheerio'); -const iconv = require('iconv-lite'); const debounce = require('promise-debounce'); const _ = require('lodash'); -const request = Promise.promisify(require('request')); const getUrlOfUser = require('./getURLOfUser'); +const axios = require('./axios'); let meetingpointData; let lastUpdate; @@ -66,13 +64,11 @@ function combineUsers(usersArrays) { function getAlts(users) { const requests = users.map(user => - request(getUrlOfUser('dag', user.type, user.index, 7), { timeout: 8000, encoding: null })); + axios.get(getUrlOfUser('dag', user.type, user.index, 7))); return Promise.all(requests).then(teacherResponses => teacherResponses.map((teacherResponse, index) => { - const teacherResponseBody = iconv.decode(teacherResponse.body, 'iso-8859-1'); - - const teacherName = scrapeAltText(teacherResponseBody); + const teacherName = scrapeAltText(teacherResponse.data); return { ...users[index], @@ -83,15 +79,15 @@ function getAlts(users) { function getScheduleData() { const navbarRequests = [ - 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 }), + axios.get('/dagroosters/frames/navbar.htm'), + axios.get('/basisroosters/frames/navbar.htm'), ]; return Promise.all(navbarRequests) .then(([dailyScheduleResponse, basisScheduleResponse]) => { - const users = scrapeUsers(dailyScheduleResponse.body); - const dailyScheduleWeeks = scrapeWeeks(dailyScheduleResponse.body); - const basisScheduleWeeks = scrapeWeeks(basisScheduleResponse.body); + const users = scrapeUsers(dailyScheduleResponse.data); + const dailyScheduleWeeks = scrapeWeeks(dailyScheduleResponse.data); + const basisScheduleWeeks = scrapeWeeks(basisScheduleResponse.data); const teachers = users.filter(user => user.type === 't'); diff --git a/src/server/lib/schools/hetmml/getURLOfUser.js b/src/server/lib/schools/hetmml/getURLOfUser.js index f44d1a3..2e1e1e9 100644 --- a/src/server/lib/schools/hetmml/getURLOfUser.js +++ b/src/server/lib/schools/hetmml/getURLOfUser.js @@ -1,8 +1,7 @@ const leftPad = require('left-pad'); // I imported this just to piss you off ;) function getURLOfUser(scheduleType, type, index, week) { - return `http://www.meetingpointmco.nl/Roosters-AL/doc/${scheduleType}roosters/` + - `${leftPad(week, 2, '0')}/${type}/${type}${leftPad(index + 1, 5, '0')}.htm`; + return `/${scheduleType}roosters/${leftPad(week, 2, '0')}/${type}/${type}${leftPad(index + 1, 5, '0')}.htm`; } module.exports = getURLOfUser; |