Added function comments on schedule.js

This commit is contained in:
Bram van der Veen 2015-06-13 22:07:06 +02:00
parent af0c2768e0
commit 913ca852c4

View file

@ -2,14 +2,15 @@
var http = require('http'); var http = require('http');
var cheerio = require('cheerio'); var cheerio = require('cheerio');
//Wrapper function that is being called by express.
function schedule(res, req, match) { function schedule(res, req, match) {
console.log();
get(req.req.match.url, function (json) { get(req.req.match.url, function (json) {
req.req.match.json = json; req.req.match.json = json;
res.res.send(json); res.res.send(json);
}); });
} }
//Function for getting the page via http.
function get(url, callback) { function get(url, callback) {
http.get(url, function (res) { http.get(url, function (res) {
var _download = ''; var _download = '';
@ -24,6 +25,7 @@ function get(url, callback) {
}); });
} }
//Function for converting the page into a json dataset.
function to_json(page) { function to_json(page) {
var result = cheerio('td:nth-child(3) table', page); var result = cheerio('td:nth-child(3) table', page);
var amount_of_days = cheerio(result).find('tr.AccentDark').find('td').length - 1; var amount_of_days = cheerio(result).find('tr.AccentDark').find('td').length - 1;
@ -57,4 +59,5 @@ function to_json(page) {
return schedule_data; return schedule_data;
} }
//Exporting the schedule function.
module.exports = schedule; module.exports = schedule;