aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-16 22:10:26 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-16 22:10:26 +0100
commit48ca524d275e05d39904a40486fb2a146eb37371 (patch)
tree1434bda422e071fa4826336cafa70224c06d9223 /src
parent84b52e8df51fd30b122d7b3542f569c0c7f4c183 (diff)
Properly remove dublicate users
Diffstat (limited to 'src')
-rw-r--r--src/server/lib/getMeetingpointData.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/server/lib/getMeetingpointData.js b/src/server/lib/getMeetingpointData.js
index 69d518f..64e8500 100644
--- a/src/server/lib/getMeetingpointData.js
+++ b/src/server/lib/getMeetingpointData.js
@@ -52,6 +52,10 @@ function getWeeks(page) {
return weeks;
}
+function getAltText(page) {
+ return page('center > font').eq(2).text().trim();
+}
+
function requestData() {
lastUpdate = new Date();
@@ -71,13 +75,14 @@ function requestData() {
const teachers = users.filter(user => user.type === 't');
const teacherRequests = teachers.map(teacher =>
- request(getUrlOfUser('dag', teacher.type, teacher.index, 7), { timeout: 5000, encoding: null }));
+ request(getUrlOfUser('dag', teacher.type, teacher.index, 7), { encoding: null }));
return Promise.all(teacherRequests).then((teacherResponses) => {
const teachersWithAlts = teacherResponses.map((teacherResponse, index) => {
const utf8Body = iconv.decode(teacherResponse.body, 'iso-8859-1');
const teacherResponseBody = cheerio.load(utf8Body);
- const teacherName = teacherResponseBody('center > font').eq(2).text().trim();
+
+ const teacherName = getAltText(teacherResponseBody);
return {
...teachers[index],
@@ -86,7 +91,7 @@ function requestData() {
});
meetingpointData = {
- users: _.defaults(teachersWithAlts, users),
+ users: _.uniqBy(_.flatten([teachersWithAlts, users]), user => `${user.type}/${user.value}`),
dailyScheduleWeeks,
basisScheduleWeeks,
};