From 7eb6126402cba36dc3105fa4dfa769e2d2b616eb Mon Sep 17 00:00:00 2001 From: Bram van der Veen <96aa48@gmail.com> Date: Sat, 15 Aug 2015 21:07:22 +0200 Subject: [PATCH] Changed ALL of 'm (all of the variable & function names) --- api.js | 10 +++---- auth.js | 20 ++++++------- configuration.js | 16 +++++------ eastereggs.json | 2 +- lookup.js | 40 +++++++++++++------------- resources/jade/schedule.jade | 8 +++--- schedule.js | 56 ++++++++++++++++++------------------ spider.js | 40 +++++++++++++------------- time.js | 12 ++++---- web.js | 10 +++---- 10 files changed, 107 insertions(+), 107 deletions(-) diff --git a/api.js b/api.js index 13a2b55..c4d2d97 100644 --- a/api.js +++ b/api.js @@ -10,7 +10,7 @@ function parse(req, res, next, api) { else { lookup.api(req, function (lookup) { 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 { 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 { - schedule.api(lookup, function (schedule_data) { - send_response(schedule_data, res, true); + schedule.api(lookup, function (scheduleData) { + sendResponse(scheduleData, res, true); }); } } @@ -39,9 +39,9 @@ function error(str, res, data) { return; } -function send_response(data, res, disable_pretty) { +function sendResponse(data, res, disablePretty) { 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); return; } diff --git a/auth.js b/auth.js index 96559a3..026c116 100644 --- a/auth.js +++ b/auth.js @@ -6,7 +6,7 @@ var crypt = require('./crypt'); var config = require('./configuration'); var lookup = require('./lookup'); -function get_login(username, password, callback) { +function getLogin(username, password, callback) { var login = qs.stringify({ GebruikersNaam : username, Wachtwoord : password @@ -21,8 +21,8 @@ function get_login(username, password, callback) { 'Content-Type' : 'application/x-www-form-urlencoded', 'Content-Length' : login.length }, - socksPort: config().tor_port, - socksHost: config().tor_host + socksPort: config().torPort, + socksHost: config().torHost }, function (res) { if (res.statusCode == 201 || res.statusCode == 200) callback(true); else callback(false); @@ -37,11 +37,11 @@ function login(req, res, next) { }); 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) { - var username = crypt.encrypt(login_information.username); - var password = crypt.encrypt(login_information.password); + getLogin(loginInformation.username, loginInformation.password, function (legit) { + var username = crypt.encrypt(loginInformation.username); + var password = crypt.encrypt(loginInformation.password); if (legit) { res.cookie('username', username); res.cookie('password', password); @@ -65,11 +65,11 @@ function is(req, res, next) { var username = crypt.decrypt(cookies.username), password = crypt.decrypt(cookies.password); - get_login(username, password, function (legit) { + getLogin(username, password, function (legit) { if (legit) { req.query.name = username; - lookup.api(req, function (database_entry) { - req.headers.user = database_entry.data[0]; + lookup.api(req, function (databaseEntry) { + req.headers.user = databaseEntry.data[0]; next(); }); } diff --git a/configuration.js b/configuration.js index 15739cd..c453d5e 100644 --- a/configuration.js +++ b/configuration.js @@ -8,11 +8,11 @@ module.exports = function () { var settings = { 'env' : 'dev', 'database' : 'example.com/database', - 'web_port' : 1024, - 'tor_host' : 'example.com', - 'tor_port' : 9050, - 'amount_of_hours' : 7, - 'hour_times' : [ + 'webPort' : 1024, + 'torHost' : 'example.com', + 'torPort' : 9050, + 'amountOfHours' : 7, + 'times' : [ '8:45 - 9:45', '9:45 - 10:45', '11:10 - 12:10', @@ -21,13 +21,13 @@ module.exports = function () { '14:40 - 15:40', '15:40 - 16:40' ], - 'school_id' : 934, + 'schoolID' : 934, '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'], 'Mail': ['https://login.microsoftonline.com/', '#C41824'] }, - 'spider_timeout' : 1000 + 'spiderTimeout' : 1000 } //Write it to file as pretty printed JSON. fs.writeFileSync(__dirname + '/settings.json', JSON.stringify(settings, null, 2)); diff --git a/eastereggs.json b/eastereggs.json index 75f241a..f1e320c 100644 --- a/eastereggs.json +++ b/eastereggs.json @@ -13,7 +13,7 @@ { "easter" : "nietzsche", "name" : "hTig", - "real_name" : "Harm Tiggelaar", + "realName" : "Harm Tiggelaar", "text" : "Docent, groot filosoof en voorbeeld in haarstijl", "type" : "RIP" }, diff --git a/lookup.js b/lookup.js index 540dffe..c3bcfc5 100644 --- a/lookup.js +++ b/lookup.js @@ -2,7 +2,7 @@ //Getting local variables via the configuration file. var config = require('./configuration'); -var school_id = config().school_id; +var schoolID = config().schoolID; //Getting first and third party modules var fs = require('fs'); @@ -14,7 +14,7 @@ function get(req, res, next, search) { easter(search) ? search = easter(search).name : null; 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 ((req.easter || {}).type == 'RIP') { @@ -22,18 +22,18 @@ function get(req, res, next, search) { res.render('schedule', req); }); } - else if (database_entry.length == 1) { - database_entry[0].url = make_url(req, database_entry[0]); - req.match = database_entry[0]; + else if (databaseEntry.length == 1) { + databaseEntry[0].url = makeUrl(req, databaseEntry[0]); + req.match = databaseEntry[0]; next(); } - else if (database_entry.length == 0) { + else if (databaseEntry.length == 0) { require('./auth').is(req, res, function () { res.render('not_found', req); }); } else { - req.match = database_entry; + req.match = databaseEntry; require('./auth').is(req, res, function () { res.render('list', req); }); @@ -45,11 +45,11 @@ function api(req, callback) { var index = database.collection('index'); 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}); else { - for (entry of database_entry) {entry.url = make_url(req, entry)} - callback({'data': database_entry}); + for (entry of databaseEntry) {entry.url = makeUrl(req, entry)} + callback({'data': databaseEntry}); } }); } @@ -58,36 +58,36 @@ function list(req, res, next, list) { var index = database.collection('index'); 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();} 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); }); - req.match = database_entry; + req.match = databaseEntry; next(); } }); } -function make_url(req, database_entry) { - 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'; +function makeUrl(req, databaseEntry) { + 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' : - url += '&afdeling=' + database_entry.studentcategory + '&leerling=' + database_entry.id; + url += '&afdeling=' + databaseEntry.studentcategory + '&leerling=' + databaseEntry.id; break; case 'docent' : - url += '&docenten=' + database_entry.name; + url += '&docenten=' + databaseEntry.name; break; case 'lokaal' : - url += '&lokalen=' + database_entry.name; + url += '&lokalen=' + databaseEntry.name; break; case 'klas' : - url += '&klassen=' + database_entry.name; + url += '&klassen=' + databaseEntry.name; break; } diff --git a/resources/jade/schedule.jade b/resources/jade/schedule.jade index e16ab0b..71a66d5 100644 --- a/resources/jade/schedule.jade +++ b/resources/jade/schedule.jade @@ -20,7 +20,7 @@ if !easter || easter.type != "RIP" .hour.title span= days[match.json.indexOf(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' .hour(class=((hour.changed == 'true' ? 'changed' : '') + (current ? ' current' : ''))) 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)] 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 .hour.changed(class= current ? ' current' : '') span.free Vrij 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 .schedule.rip h1 R.I.P - p="Hier ligt " + (easter.real_name || easter.name) + p="Hier ligt " + (easter.realName || easter.name) sup="aka " + easter.easter p=easter.text p Voor altijd in ons hart diff --git a/schedule.js b/schedule.js index d43821c..00b60ba 100644 --- a/schedule.js +++ b/schedule.js @@ -6,21 +6,21 @@ var url = require('url'); //Wrapper function that is being called by express. function get(req, res, next) { - get_schedule(req.match.url, function (json) { + getSchedule(req.match.url, function (json) { req.match.json = json; next(); }); } 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 get_schedule(get_url, callback) { - var options = url.parse(get_url); - options.socksPort = config().tor_port; - options.socksHost = config().tor_host; +function getSchedule(getUrl, callback) { + var options = url.parse(getUrl); + options.socksPort = config().torPort; + options.socksHost = config().torHost; http.get(options, function (res) { var _download = ''; @@ -30,12 +30,12 @@ function get_schedule(get_url, callback) { }); 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 tab = 0; var types = []; @@ -52,43 +52,43 @@ function schedule_types(page) { } //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 types = schedule_types(page); - var is_teacher = 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 amount_of_hours = config().amount_of_hours; + var types = types(page); + var isTeacher = cheerio(cheerio(page).find('tr.CoreDark').find('td')[3]).find('a').html() == null; + var amountOfDays = cheerio(result).find('tr.AccentDark').find('td').length - 1; + 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 - for (day = 0; day < amount_of_days; day++) { - schedule_data[day] = []; + for (day = 0; day < amountOfDays; day++) { + scheduleData[day] = []; //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); //Looping for (optional) specialhours - var amount_of_special_hours = schedule.find('table').eq(day).children().length; - schedule_data[day][hour] = {teacher: [], chamber: [], course: [], changed: []}; - for (subhour = 0; subhour < amount_of_special_hours; subhour++) { - var selected_hour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td'); + var specialHours = schedule.find('table').eq(day).children().length; + scheduleData[day][hour] = {teacher: [], chamber: [], course: [], changed: []}; + for (subhour = 0; subhour < specialHours; subhour++) { + var selectedHour = schedule.find('table').eq(day).find('tr').eq(subhour).find('td'); //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, ''); - schedule_data[day][hour].chamber[subhour] = selected_hour.eq(2).text(); - schedule_data[day][hour].course[subhour] = selected_hour.eq(4).text(); + scheduleData[day][hour].teacher[subhour] = selectedHour.eq(0).text().replace(/\r|\n/g, ''); + scheduleData[day][hour].chamber[subhour] = selectedHour.eq(2).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. - 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. diff --git a/spider.js b/spider.js index a46bd0b..7a7fea5 100644 --- a/spider.js +++ b/spider.js @@ -11,7 +11,7 @@ var scheduletypes = [ 'Leerlingrooster', 'Lokaalrooster' ]; -var school_id; +var schoolID; var database; //Function for getting pages with http requests. @@ -22,9 +22,9 @@ function get() { (function (scheduletype) { - var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + scheduletype); - options.socksPort = config().tor_port; - options.socksHost = config().tor_host; + var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + scheduletype); + options.socksPort = config().torPort; + options.socksHost = config().torHost; http.get(options, function (res) { @@ -61,9 +61,9 @@ function rip(data) { for(studentcategory of list) { (function (studentcategory) { - var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + school_id + '&type=' + data.type + '&afdeling=' + studentcategory); - options.socksPort = config().tor_port; - options.socksHost = config().tor_host; + var options = url.parse('http://roosters5.gepro-osi.nl/roosters/rooster.php?school=' + schoolID + '&type=' + data.type + '&afdeling=' + studentcategory); + options.socksPort = config().torPort; + options.socksHost = config().torHost; http.get(options, function (res) { var _download = ''; @@ -73,16 +73,16 @@ function rip(data) { }); 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)) { - var name = cheerio(list_students[student]).text().split(' - ')[1]; - var group = cheerio(list_students[student]).text().split(' - ')[0]; - var id = cheerio(list_students[student]).val(); + var name = cheerio(listOfStudents[student]).text().split(' - ')[1]; + var group = cheerio(listOfStudents[student]).text().split(' - ')[0]; + var id = cheerio(listOfStudents[student]).val(); - var database_entry = { + var databaseEntry = { 'id' : id, 'group' : group, 'username' : id + name.split(' ')[0].toLowerCase(), @@ -93,12 +93,12 @@ function rip(data) { '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 () { database.close(); - }, config().spider_timeout); + }, config().spiderTimeout); } } @@ -110,19 +110,19 @@ function rip(data) { } else { for (entry of list) { - var database_entry = { + var databaseEntry = { 'name' : entry, '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 crawl() { - school_id = config().school_id; + schoolID = config().schoolID; mongodb.connect('mongodb://' + config().database, function (error, db) { if (error) console.warn(error); database = db; @@ -133,7 +133,7 @@ function crawl() { //Redundant function for draining native-mongodb-driver output -function show_output(error, message) { +function showOutput(error, message) { if (process.argv[3] == '-v') { // if (error) process.stdout.write(error.toString()); if (message != null) console.log(message); diff --git a/time.js b/time.js index 058f464..7fde237 100644 --- a/time.js +++ b/time.js @@ -20,14 +20,14 @@ function parse(timestr) { } //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; else return false; } -function during_school() { - var start = parse(config().hour_times[0])[0]; - var end = parse(config().hour_times[config().hour_times.length - 1])[1]; +function duringSchool() { + var start = parse(config().times[0])[0]; + var end = parse(config().times[config().times.length - 1])[1]; if (get() > start && get() < end) return true; else return false; @@ -35,6 +35,6 @@ function during_school() { module.exports = { 'get': get, - 'within_timespan': within_timespan, - 'during_school': during_school + 'withinTimespan': withinTimespan, + 'duringSchool': duringSchool } diff --git a/web.js b/web.js index 9b141ee..71b37a8 100644 --- a/web.js +++ b/web.js @@ -21,7 +21,7 @@ app.set('views', __dirname + '/resources/jade'); //Give the app some configuration information app.locals.linkbar = config().linkbar; -app.locals.hour_times = config().hour_times; +app.locals.times = config().times; app.locals.time = time; //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); }]); -app.listen(config().web_port); +app.listen(config().webPort); 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'; 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))); } } }