Changed ALL of 'm (all of the variable & function names)
This commit is contained in:
parent
d7192b8e6d
commit
7eb6126402
10
api.js
10
api.js
|
@ -10,7 +10,7 @@ function parse(req, res, next, api) {
|
||||||
else {
|
else {
|
||||||
lookup.api(req, function (lookup) {
|
lookup.api(req, function (lookup) {
|
||||||
if (lookup.error) error(lookup.error, res);
|
if (lookup.error) error(lookup.error, res);
|
||||||
else send_response(lookup.data, res);
|
else sendResponse(lookup.data, res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ function parse(req, res, next, api) {
|
||||||
else {
|
else {
|
||||||
if (lookup.data.length > 1 || lookup.data.length == 0) error('The request that you did had multiple responses or none, make sure that your query returns one.', res, lookup.data)
|
if (lookup.data.length > 1 || lookup.data.length == 0) error('The request that you did had multiple responses or none, make sure that your query returns one.', res, lookup.data)
|
||||||
else {
|
else {
|
||||||
schedule.api(lookup, function (schedule_data) {
|
schedule.api(lookup, function (scheduleData) {
|
||||||
send_response(schedule_data, res, true);
|
sendResponse(scheduleData, res, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ function error(str, res, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_response(data, res, disable_pretty) {
|
function sendResponse(data, res, disablePretty) {
|
||||||
res.set('Content-Type', 'application/json');
|
res.set('Content-Type', 'application/json');
|
||||||
var response = JSON.stringify({'data': data}, null, disable_pretty ? 0 : 2);
|
var response = JSON.stringify({'data': data}, null, disablePretty ? 0 : 2);
|
||||||
res.status(200).end(response);
|
res.status(200).end(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
20
auth.js
20
auth.js
|
@ -6,7 +6,7 @@ var crypt = require('./crypt');
|
||||||
var config = require('./configuration');
|
var config = require('./configuration');
|
||||||
var lookup = require('./lookup');
|
var lookup = require('./lookup');
|
||||||
|
|
||||||
function get_login(username, password, callback) {
|
function getLogin(username, password, callback) {
|
||||||
var login = qs.stringify({
|
var login = qs.stringify({
|
||||||
GebruikersNaam : username,
|
GebruikersNaam : username,
|
||||||
Wachtwoord : password
|
Wachtwoord : password
|
||||||
|
@ -21,8 +21,8 @@ function get_login(username, password, callback) {
|
||||||
'Content-Type' : 'application/x-www-form-urlencoded',
|
'Content-Type' : 'application/x-www-form-urlencoded',
|
||||||
'Content-Length' : login.length
|
'Content-Length' : login.length
|
||||||
},
|
},
|
||||||
socksPort: config().tor_port,
|
socksPort: config().torPort,
|
||||||
socksHost: config().tor_host
|
socksHost: config().torHost
|
||||||
}, function (res) {
|
}, function (res) {
|
||||||
if (res.statusCode == 201 || res.statusCode == 200) callback(true);
|
if (res.statusCode == 201 || res.statusCode == 200) callback(true);
|
||||||
else callback(false);
|
else callback(false);
|
||||||
|
@ -37,11 +37,11 @@ function login(req, res, next) {
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('end', function () {
|
req.on('end', function () {
|
||||||
var login_information = qs.parse(_data)
|
var loginInformation = qs.parse(_data)
|
||||||
|
|
||||||
get_login(login_information.username, login_information.password, function (legit) {
|
getLogin(loginInformation.username, loginInformation.password, function (legit) {
|
||||||
var username = crypt.encrypt(login_information.username);
|
var username = crypt.encrypt(loginInformation.username);
|
||||||
var password = crypt.encrypt(login_information.password);
|
var password = crypt.encrypt(loginInformation.password);
|
||||||
if (legit) {
|
if (legit) {
|
||||||
res.cookie('username', username);
|
res.cookie('username', username);
|
||||||
res.cookie('password', password);
|
res.cookie('password', password);
|
||||||
|
@ -65,11 +65,11 @@ function is(req, res, next) {
|
||||||
var username = crypt.decrypt(cookies.username),
|
var username = crypt.decrypt(cookies.username),
|
||||||
password = crypt.decrypt(cookies.password);
|
password = crypt.decrypt(cookies.password);
|
||||||
|
|
||||||
get_login(username, password, function (legit) {
|
getLogin(username, password, function (legit) {
|
||||||
if (legit) {
|
if (legit) {
|
||||||
req.query.name = username;
|
req.query.name = username;
|
||||||
lookup.api(req, function (database_entry) {
|
lookup.api(req, function (databaseEntry) {
|
||||||
req.headers.user = database_entry.data[0];
|
req.headers.user = databaseEntry.data[0];
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ module.exports = function () {
|
||||||
var settings = {
|
var settings = {
|
||||||
'env' : 'dev',
|
'env' : 'dev',
|
||||||
'database' : 'example.com/database',
|
'database' : 'example.com/database',
|
||||||
'web_port' : 1024,
|
'webPort' : 1024,
|
||||||
'tor_host' : 'example.com',
|
'torHost' : 'example.com',
|
||||||
'tor_port' : 9050,
|
'torPort' : 9050,
|
||||||
'amount_of_hours' : 7,
|
'amountOfHours' : 7,
|
||||||
'hour_times' : [
|
'times' : [
|
||||||
'8:45 - 9:45',
|
'8:45 - 9:45',
|
||||||
'9:45 - 10:45',
|
'9:45 - 10:45',
|
||||||
'11:10 - 12:10',
|
'11:10 - 12:10',
|
||||||
|
@ -21,13 +21,13 @@ module.exports = function () {
|
||||||
'14:40 - 15:40',
|
'14:40 - 15:40',
|
||||||
'15:40 - 16:40'
|
'15:40 - 16:40'
|
||||||
],
|
],
|
||||||
'school_id' : 934,
|
'schoolID' : 934,
|
||||||
'linkbar' : {
|
'linkbar' : {
|
||||||
'Roostersite': ['http://roosters5.gepro-osi.nl/roosters/rooster.php?school=INSERTYOURSCHOOL_ID', '#CCCC99'],
|
'Roostersite': ['http://roosters5.gepro-osi.nl/roosters/rooster.php?school=INSERTYOURSCHOOLID', '#CCCC99'],
|
||||||
'Magister': ['http://INSERTYOURMAGISTER.magister.net', '#0C5489'],
|
'Magister': ['http://INSERTYOURMAGISTER.magister.net', '#0C5489'],
|
||||||
'Mail': ['https://login.microsoftonline.com/', '#C41824']
|
'Mail': ['https://login.microsoftonline.com/', '#C41824']
|
||||||
},
|
},
|
||||||
'spider_timeout' : 1000
|
'spiderTimeout' : 1000
|
||||||
}
|
}
|
||||||
//Write it to file as pretty printed JSON.
|
//Write it to file as pretty printed JSON.
|
||||||
fs.writeFileSync(__dirname + '/settings.json', JSON.stringify(settings, null, 2));
|
fs.writeFileSync(__dirname + '/settings.json', JSON.stringify(settings, null, 2));
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
{
|
{
|
||||||
"easter" : "nietzsche",
|
"easter" : "nietzsche",
|
||||||
"name" : "hTig",
|
"name" : "hTig",
|
||||||
"real_name" : "Harm Tiggelaar",
|
"realName" : "Harm Tiggelaar",
|
||||||
"text" : "Docent, groot filosoof en voorbeeld in haarstijl",
|
"text" : "Docent, groot filosoof en voorbeeld in haarstijl",
|
||||||
"type" : "RIP"
|
"type" : "RIP"
|
||||||
},
|
},
|
||||||
|
|
40
lookup.js
40
lookup.js
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//Getting local variables via the configuration file.
|
//Getting local variables via the configuration file.
|
||||||
var config = require('./configuration');
|
var config = require('./configuration');
|
||||||
var school_id = config().school_id;
|
var schoolID = config().schoolID;
|
||||||
|
|
||||||
//Getting first and third party modules
|
//Getting first and third party modules
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
@ -14,7 +14,7 @@ function get(req, res, next, search) {
|
||||||
easter(search) ? search = easter(search).name : null;
|
easter(search) ? search = easter(search).name : null;
|
||||||
search = new RegExp(search, 'i');
|
search = new RegExp(search, 'i');
|
||||||
|
|
||||||
index.find({$or : [{id : search}, {name : search}, {first_name : search}, {last_name : search}, {username: search}]}).toArray(function (err, database_entry) {
|
index.find({$or : [{id : search}, {name : search}, {first_name : search}, {last_name : search}, {username: search}]}).toArray(function (err, databaseEntry) {
|
||||||
if (err) console.warn(err);
|
if (err) console.warn(err);
|
||||||
|
|
||||||
if ((req.easter || {}).type == 'RIP') {
|
if ((req.easter || {}).type == 'RIP') {
|
||||||
|
@ -22,18 +22,18 @@ function get(req, res, next, search) {
|
||||||
res.render('schedule', req);
|
res.render('schedule', req);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (database_entry.length == 1) {
|
else if (databaseEntry.length == 1) {
|
||||||
database_entry[0].url = make_url(req, database_entry[0]);
|
databaseEntry[0].url = makeUrl(req, databaseEntry[0]);
|
||||||
req.match = database_entry[0];
|
req.match = databaseEntry[0];
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
else if (database_entry.length == 0) {
|
else if (databaseEntry.length == 0) {
|
||||||
require('./auth').is(req, res, function () {
|
require('./auth').is(req, res, function () {
|
||||||
res.render('not_found', req);
|
res.render('not_found', req);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
req.match = database_entry;
|
req.match = databaseEntry;
|
||||||
require('./auth').is(req, res, function () {
|
require('./auth').is(req, res, function () {
|
||||||
res.render('list', req);
|
res.render('list', req);
|
||||||
});
|
});
|
||||||
|
@ -45,11 +45,11 @@ function api(req, callback) {
|
||||||
var index = database.collection('index');
|
var index = database.collection('index');
|
||||||
var query = RegExp(req.query.name, 'i');
|
var query = RegExp(req.query.name, 'i');
|
||||||
|
|
||||||
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}, {group: query}]}).toArray(function (err, database_entry) {
|
index.find({$or : [{id : query}, {name : query}, {first_name : query}, {last_name : query}, {username: query}, {group: query}]}).toArray(function (err, databaseEntry) {
|
||||||
if (err) callback({'error': err});
|
if (err) callback({'error': err});
|
||||||
else {
|
else {
|
||||||
for (entry of database_entry) {entry.url = make_url(req, entry)}
|
for (entry of databaseEntry) {entry.url = makeUrl(req, entry)}
|
||||||
callback({'data': database_entry});
|
callback({'data': databaseEntry});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -58,36 +58,36 @@ function list(req, res, next, list) {
|
||||||
var index = database.collection('index');
|
var index = database.collection('index');
|
||||||
var query = RegExp(list, 'i');
|
var query = RegExp(list, 'i');
|
||||||
|
|
||||||
index.find({group: list}).toArray(function (err, database_entry) {
|
index.find({group: list}).toArray(function (err, databaseEntry) {
|
||||||
if (err) {req.error = err; next();}
|
if (err) {req.error = err; next();}
|
||||||
else {
|
else {
|
||||||
if (database_entry.length < 1) require('./auth').is(req, res, function () {
|
if (databaseEntry.length < 1) require('./auth').is(req, res, function () {
|
||||||
res.render('not_found', req);
|
res.render('not_found', req);
|
||||||
});
|
});
|
||||||
req.match = database_entry;
|
req.match = databaseEntry;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_url(req, database_entry) {
|
function makeUrl(req, databaseEntry) {
|
||||||
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + database_entry.type.charAt(0).toUpperCase() + database_entry.type.slice(1) + 'rooster';
|
var url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + databaseEntry.type.charAt(0).toUpperCase() + databaseEntry.type.slice(1) + 'rooster';
|
||||||
|
|
||||||
switch (database_entry.type) {
|
switch (databaseEntry.type) {
|
||||||
case 'leerling' :
|
case 'leerling' :
|
||||||
url += '&afdeling=' + database_entry.studentcategory + '&leerling=' + database_entry.id;
|
url += '&afdeling=' + databaseEntry.studentcategory + '&leerling=' + databaseEntry.id;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'docent' :
|
case 'docent' :
|
||||||
url += '&docenten=' + database_entry.name;
|
url += '&docenten=' + databaseEntry.name;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'lokaal' :
|
case 'lokaal' :
|
||||||
url += '&lokalen=' + database_entry.name;
|
url += '&lokalen=' + databaseEntry.name;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'klas' :
|
case 'klas' :
|
||||||
url += '&klassen=' + database_entry.name;
|
url += '&klassen=' + databaseEntry.name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ if !easter || easter.type != "RIP"
|
||||||
.hour.title
|
.hour.title
|
||||||
span= days[match.json.indexOf(day)]
|
span= days[match.json.indexOf(day)]
|
||||||
each hour in day
|
each hour in day
|
||||||
- var current = app.locals.time.within_timespan(app.locals.hour_times[day.indexOf(hour)]);
|
- var current = app.locals.time.withinTimespan(app.locals.times[day.indexOf(hour)]);
|
||||||
if hour.teacher != 'vrij'
|
if hour.teacher != 'vrij'
|
||||||
.hour(class=((hour.changed == 'true' ? 'changed' : '') + (current ? ' current' : '')))
|
.hour(class=((hour.changed == 'true' ? 'changed' : '') + (current ? ' current' : '')))
|
||||||
each subhour in hour.teacher
|
each subhour in hour.teacher
|
||||||
|
@ -31,17 +31,17 @@ if !easter || easter.type != "RIP"
|
||||||
span.course(class='sub_' + hour.teacher.length)= hour.course[hour.teacher.indexOf(subhour)]
|
span.course(class='sub_' + hour.teacher.length)= hour.course[hour.teacher.indexOf(subhour)]
|
||||||
|
|
||||||
if match.json.indexOf(day) == 0
|
if match.json.indexOf(day) == 0
|
||||||
span.time= app.locals.hour_times[match.json[0].indexOf(hour)]
|
span.time= app.locals.times[match.json[0].indexOf(hour)]
|
||||||
|
|
||||||
else
|
else
|
||||||
.hour.changed(class= current ? ' current' : '')
|
.hour.changed(class= current ? ' current' : '')
|
||||||
span.free Vrij
|
span.free Vrij
|
||||||
if match.json.indexOf(day) == 0
|
if match.json.indexOf(day) == 0
|
||||||
span.time= app.locals.hour_times[match.json[0].indexOf(hour)]
|
span.time= app.locals.times[match.json[0].indexOf(hour)]
|
||||||
else
|
else
|
||||||
.schedule.rip
|
.schedule.rip
|
||||||
h1 R.I.P
|
h1 R.I.P
|
||||||
p="Hier ligt " + (easter.real_name || easter.name)
|
p="Hier ligt " + (easter.realName || easter.name)
|
||||||
sup="aka " + easter.easter
|
sup="aka " + easter.easter
|
||||||
p=easter.text
|
p=easter.text
|
||||||
p Voor altijd in ons hart
|
p Voor altijd in ons hart
|
||||||
|
|
56
schedule.js
56
schedule.js
|
@ -6,21 +6,21 @@ var url = require('url');
|
||||||
|
|
||||||
//Wrapper function that is being called by express.
|
//Wrapper function that is being called by express.
|
||||||
function get(req, res, next) {
|
function get(req, res, next) {
|
||||||
get_schedule(req.match.url, function (json) {
|
getSchedule(req.match.url, function (json) {
|
||||||
req.match.json = json;
|
req.match.json = json;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function api(lookup, callback) {
|
function api(lookup, callback) {
|
||||||
get_schedule(lookup.data[0].url, callback);
|
getSchedule(lookup.data[0].url, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Function for getting the page via http.
|
//Function for getting the page via http.
|
||||||
function get_schedule(get_url, callback) {
|
function getSchedule(getUrl, callback) {
|
||||||
var options = url.parse(get_url);
|
var options = url.parse(getUrl);
|
||||||
options.socksPort = config().tor_port;
|
options.socksPort = config().torPort;
|
||||||
options.socksHost = config().tor_host;
|
options.socksHost = config().torHost;
|
||||||
|
|
||||||
http.get(options, function (res) {
|
http.get(options, function (res) {
|
||||||
var _download = '';
|
var _download = '';
|
||||||
|
@ -30,12 +30,12 @@ function get_schedule(get_url, callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function () {
|
res.on('end', function () {
|
||||||
callback(to_json(_download));
|
callback(toJSON(_download));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function schedule_types(page) {
|
function types(page) {
|
||||||
var extract = cheerio('table tr td[valign="bottom"] table tr td b, table tr td[valign="bottom"] table tr td a', page).text().split(/\s\s/);
|
var extract = cheerio('table tr td[valign="bottom"] table tr td b, table tr td[valign="bottom"] table tr td a', page).text().split(/\s\s/);
|
||||||
var tab = 0;
|
var tab = 0;
|
||||||
var types = [];
|
var types = [];
|
||||||
|
@ -52,43 +52,43 @@ function schedule_types(page) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Function for converting the page into a json dataset.
|
//Function for converting the page into a json dataset.
|
||||||
function to_json(page) {
|
function toJSON(page) {
|
||||||
var result = cheerio('td:nth-child(3) table', page);
|
var result = cheerio('td:nth-child(3) table', page);
|
||||||
var types = schedule_types(page);
|
var types = types(page);
|
||||||
var is_teacher = cheerio(cheerio(page).find('tr.CoreDark').find('td')[3]).find('a').html() == null;
|
var isTeacher = cheerio(cheerio(page).find('tr.CoreDark').find('td')[3]).find('a').html() == null;
|
||||||
var amount_of_days = cheerio(result).find('tr.AccentDark').find('td').length - 1;
|
var amountOfDays = cheerio(result).find('tr.AccentDark').find('td').length - 1;
|
||||||
var amount_of_hours = config().amount_of_hours;
|
var amountOfHours = config().amountOfHours;
|
||||||
|
|
||||||
var schedule_data = [];
|
var scheduleData = [];
|
||||||
|
|
||||||
var offset = is_teacher ? 5 : 6;
|
var offset = isTeacher ? 5 : 6;
|
||||||
|
|
||||||
//Looping for amount of days
|
//Looping for amount of days
|
||||||
for (day = 0; day < amount_of_days; day++) {
|
for (day = 0; day < amountOfDays; day++) {
|
||||||
schedule_data[day] = [];
|
scheduleData[day] = [];
|
||||||
|
|
||||||
//Looping for amount of hours
|
//Looping for amount of hours
|
||||||
for (hour = 0; hour < amount_of_hours; hour++) {
|
for (hour = 0; hour < amountOfHours; hour++) {
|
||||||
var schedule = cheerio('tr:nth-child('+ (offset + hour) +')', result);
|
var schedule = cheerio('tr:nth-child('+ (offset + hour) +')', result);
|
||||||
|
|
||||||
//Looping for (optional) specialhours
|
//Looping for (optional) specialhours
|
||||||
var amount_of_special_hours = schedule.find('table').eq(day).children().length;
|
var specialHours = schedule.find('table').eq(day).children().length;
|
||||||
schedule_data[day][hour] = {teacher: [], chamber: [], course: [], changed: []};
|
scheduleData[day][hour] = {teacher: [], chamber: [], course: [], changed: []};
|
||||||
for (subhour = 0; subhour < amount_of_special_hours; subhour++) {
|
for (subhour = 0; subhour < specialHours; subhour++) {
|
||||||
var selected_hour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td');
|
var selectedHour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td');
|
||||||
//Give the value of the schedule hour to the fitting array.
|
//Give the value of the schedule hour to the fitting array.
|
||||||
schedule_data[day][hour].teacher[subhour] = selected_hour.eq(0).text().replace(/\r|\n/g, '');
|
scheduleData[day][hour].teacher[subhour] = selectedHour.eq(0).text().replace(/\r|\n/g, '');
|
||||||
schedule_data[day][hour].chamber[subhour] = selected_hour.eq(2).text();
|
scheduleData[day][hour].chamber[subhour] = selectedHour.eq(2).text();
|
||||||
schedule_data[day][hour].course[subhour] = selected_hour.eq(4).text();
|
scheduleData[day][hour].course[subhour] = selectedHour.eq(4).text();
|
||||||
//Check if the hour is 'changed' by the schedule authors, if so set to true.
|
//Check if the hour is 'changed' by the schedule authors, if so set to true.
|
||||||
schedule_data[day][hour].changed[subhour] = selected_hour.eq(0).attr().class == 'tableCellNew' ? true : false;
|
scheduleData[day][hour].changed[subhour] = selectedHour.eq(0).attr().class == 'tableCellNew' ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule_data.types = types;
|
scheduleData.types = types;
|
||||||
|
|
||||||
return schedule_data;
|
return scheduleData;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Exporting the schedule function.
|
//Exporting the schedule function.
|
||||||
|
|
40
spider.js
40
spider.js
|
@ -11,7 +11,7 @@ var scheduletypes = [
|
||||||
'Leerlingrooster',
|
'Leerlingrooster',
|
||||||
'Lokaalrooster'
|
'Lokaalrooster'
|
||||||
];
|
];
|
||||||
var school_id;
|
var schoolID;
|
||||||
var database;
|
var database;
|
||||||
|
|
||||||
//Function for getting pages with http requests.
|
//Function for getting pages with http requests.
|
||||||
|
@ -22,9 +22,9 @@ function get() {
|
||||||
|
|
||||||
(function (scheduletype) {
|
(function (scheduletype) {
|
||||||
|
|
||||||
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + scheduletype);
|
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + scheduletype);
|
||||||
options.socksPort = config().tor_port;
|
options.socksPort = config().torPort;
|
||||||
options.socksHost = config().tor_host;
|
options.socksHost = config().torHost;
|
||||||
|
|
||||||
http.get(options, function (res) {
|
http.get(options, function (res) {
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ function rip(data) {
|
||||||
for(studentcategory of list) {
|
for(studentcategory of list) {
|
||||||
|
|
||||||
(function (studentcategory) {
|
(function (studentcategory) {
|
||||||
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + data.type + '&afdeling=' + studentcategory);
|
var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + data.type + '&afdeling=' + studentcategory);
|
||||||
options.socksPort = config().tor_port;
|
options.socksPort = config().torPort;
|
||||||
options.socksHost = config().tor_host;
|
options.socksHost = config().torHost;
|
||||||
|
|
||||||
http.get(options, function (res) {
|
http.get(options, function (res) {
|
||||||
var _download = '';
|
var _download = '';
|
||||||
|
@ -73,16 +73,16 @@ function rip(data) {
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function () {
|
res.on('end', function () {
|
||||||
var list_students = cheerio('select', _download).children();
|
var listOfStudents = cheerio('select', _download).children();
|
||||||
|
|
||||||
for (student in list_students) {
|
for (student in listOfStudents) {
|
||||||
|
|
||||||
if (!isNaN(student)) {
|
if (!isNaN(student)) {
|
||||||
var name = cheerio(list_students[student]).text().split(' - ')[1];
|
var name = cheerio(listOfStudents[student]).text().split(' - ')[1];
|
||||||
var group = cheerio(list_students[student]).text().split(' - ')[0];
|
var group = cheerio(listOfStudents[student]).text().split(' - ')[0];
|
||||||
var id = cheerio(list_students[student]).val();
|
var id = cheerio(listOfStudents[student]).val();
|
||||||
|
|
||||||
var database_entry = {
|
var databaseEntry = {
|
||||||
'id' : id,
|
'id' : id,
|
||||||
'group' : group,
|
'group' : group,
|
||||||
'username' : id + name.split(' ')[0].toLowerCase(),
|
'username' : id + name.split(' ')[0].toLowerCase(),
|
||||||
|
@ -93,12 +93,12 @@ function rip(data) {
|
||||||
'type' : data.type.replace(/rooster/g, '').toLowerCase()
|
'type' : data.type.replace(/rooster/g, '').toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.insert(database_entry, show_output);
|
collection.insert(databaseEntry, showOutput);
|
||||||
|
|
||||||
if (studentcategory == list[list.length - 1] && student == list_students.length - 1) {
|
if (studentcategory == list[list.length - 1] && student == listOfStudents.length - 1) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
database.close();
|
database.close();
|
||||||
}, config().spider_timeout);
|
}, config().spiderTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,19 +110,19 @@ function rip(data) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (entry of list) {
|
for (entry of list) {
|
||||||
var database_entry = {
|
var databaseEntry = {
|
||||||
'name' : entry,
|
'name' : entry,
|
||||||
'type' : data.type.replace(/rooster/g, '').toLowerCase()
|
'type' : data.type.replace(/rooster/g, '').toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.insert(database_entry, show_output);
|
collection.insert(databaseEntry, showOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Function being called to access functionality from this module.
|
//Function being called to access functionality from this module.
|
||||||
function crawl() {
|
function crawl() {
|
||||||
school_id = config().school_id;
|
schoolID = config().schoolID;
|
||||||
mongodb.connect('mongodb://' + config().database, function (error, db) {
|
mongodb.connect('mongodb://' + config().database, function (error, db) {
|
||||||
if (error) console.warn(error);
|
if (error) console.warn(error);
|
||||||
database = db;
|
database = db;
|
||||||
|
@ -133,7 +133,7 @@ function crawl() {
|
||||||
|
|
||||||
|
|
||||||
//Redundant function for draining native-mongodb-driver output
|
//Redundant function for draining native-mongodb-driver output
|
||||||
function show_output(error, message) {
|
function showOutput(error, message) {
|
||||||
if (process.argv[3] == '-v') {
|
if (process.argv[3] == '-v') {
|
||||||
// if (error) process.stdout.write(error.toString());
|
// if (error) process.stdout.write(error.toString());
|
||||||
if (message != null) console.log(message);
|
if (message != null) console.log(message);
|
||||||
|
|
12
time.js
12
time.js
|
@ -20,14 +20,14 @@ function parse(timestr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Function for parsing and checking if the currrent time is within the parsed string.
|
//Function for parsing and checking if the currrent time is within the parsed string.
|
||||||
function within_timespan(timespan) {
|
function withinTimespan(timespan) {
|
||||||
if (get() > parse(timespan)[0] && get() < parse(timespan)[1]) return true;
|
if (get() > parse(timespan)[0] && get() < parse(timespan)[1]) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function during_school() {
|
function duringSchool() {
|
||||||
var start = parse(config().hour_times[0])[0];
|
var start = parse(config().times[0])[0];
|
||||||
var end = parse(config().hour_times[config().hour_times.length - 1])[1];
|
var end = parse(config().times[config().times.length - 1])[1];
|
||||||
|
|
||||||
if (get() > start && get() < end) return true;
|
if (get() > start && get() < end) return true;
|
||||||
else return false;
|
else return false;
|
||||||
|
@ -35,6 +35,6 @@ function during_school() {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'get': get,
|
'get': get,
|
||||||
'within_timespan': within_timespan,
|
'withinTimespan': withinTimespan,
|
||||||
'during_school': during_school
|
'duringSchool': duringSchool
|
||||||
}
|
}
|
||||||
|
|
10
web.js
10
web.js
|
@ -21,7 +21,7 @@ app.set('views', __dirname + '/resources/jade');
|
||||||
|
|
||||||
//Give the app some configuration information
|
//Give the app some configuration information
|
||||||
app.locals.linkbar = config().linkbar;
|
app.locals.linkbar = config().linkbar;
|
||||||
app.locals.hour_times = config().hour_times;
|
app.locals.times = config().times;
|
||||||
app.locals.time = time;
|
app.locals.time = time;
|
||||||
|
|
||||||
//Set up all static directories for getting resources.
|
//Set up all static directories for getting resources.
|
||||||
|
@ -57,16 +57,16 @@ app.get('/klassenlijst/:list',[auth.is, function (req, res) {
|
||||||
res.render('list', req);
|
res.render('list', req);
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
app.listen(config().web_port);
|
app.listen(config().webPort);
|
||||||
plugins();
|
plugins();
|
||||||
|
|
||||||
function plugins() {
|
function plugins() {
|
||||||
var plugins_directory = fs.readdirSync(__dirname + '/plugins');
|
var pluginsDirectory = fs.readdirSync(__dirname + '/plugins');
|
||||||
|
|
||||||
for (plugin of plugins_directory) {
|
for (plugin of pluginsDirectory) {
|
||||||
var app = __dirname + '/plugins/' + plugin + '/app.js';
|
var app = __dirname + '/plugins/' + plugin + '/app.js';
|
||||||
if (fs.existsSync(app)) {
|
if (fs.existsSync(app)) {
|
||||||
var app = require(app)(config().web_port + (1 + plugin.indexOf(plugins_directory)));
|
var app = require(app)(config().webPort + (1 + plugin.indexOf(pluginsDirectory)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue