diff --git a/lib/events.js b/lib/events.js index c4939d3..d628934 100644 --- a/lib/events.js +++ b/lib/events.js @@ -1,4 +1,7 @@ -const http = require('http'), request = require('request'), cheerio = require('cheerio'); +const http = require('http'); +const request = require('request'); +const cheerio = require('cheerio'); +const logger = require('log4js').getLogger('Events'); const eventTimer = 0; const eventCache = { @@ -12,11 +15,11 @@ const eventCache = { const cinemas = [{ 'id': 'cwr', 'url': 'https://film.list.co.uk/cinema/14982-cineworld-renfrew-street/' }, { 'id': 'gsc', 'url': 'https://film.list.co.uk/cinema/13590-cineworld-glasgow-science-centre/' }, { 'id': 'pho', 'url': 'https://film.list.co.uk/cinema/12500-showcase-cinema-paisley/' }, - {'id':'evr', 'url':'https://film.list.co.uk/cinema/111845-everyman-glasgow/'}]; + { 'id':'evr', 'url':'https://film.list.co.uk/cinema/111845-everyman-glasgow/' }]; module.exports = { 'getEvents': function (req, res) { - console.log('Getting events...'); + logger.debug('Getting events...'); const j = [], url = 'https://www.list.co.uk/events/days-out/when:this%20weekend/location:Dumbarton(55.9460,-4.5556)/distance:20/'; const now = new Date(); @@ -26,8 +29,8 @@ module.exports = { if (err) throw err; $ = cheerio.load(body); - // console.log($); - // TODO: scraping goes here! + // logger.debug($); + // TODO: scraping goes here! $('.resultsRow').each(function (div) { const item = {}; @@ -61,7 +64,7 @@ module.exports = { } }); else { - console.log('Using event cache...'); + logger.info('Using event cache...'); res.render('pages/events', eventCache); } @@ -70,18 +73,19 @@ module.exports = { const cinemaID = cinemas[id].id; const url = cinemas[id].url; const thisCinema = eventCache[cinemaID] || { 'data': {}, 'last': 0 }; - console.log(cinemaID); - console.log(url); + logger.debug(cinemaID); + logger.debug(url); const j = []; const now = new Date(); if ((now - thisCinema.last) > eventCache.expire) request(url, function (err, resp, body) { - console.log('Working'); - if (err) + logger.debug('Working'); + if (err) throw err; - $ = cheerio.load(body); + + const $ = cheerio.load(body); $('.byEvent').each(function (div) { const item = {}; @@ -102,24 +106,24 @@ module.exports = { thisCinema.data = j; eventCache[cinemaID] = thisCinema; - console.log('returning'); + logger.debug('returning'); return thisCinema; - }, function(error, response, body) { + }, (error, response, body) => { if(response.statusCode !== 200) { console.error(response.statusCode); console.error(body); } }); else { - console.log('Using event cache...'); + logger.debug('Using event cache...'); return thisCinema; } }, 'getCinema': function (req, res) { const id = parseInt(req.params.id); - console.log(`Getting cinema: ${ id}`); + logger.debug(`Getting cinema: ${ id}`); const output = module.exports.doGetCinema(id); res.render('pages/cinema', output); @@ -128,6 +132,7 @@ module.exports = { let output = module.exports.doGetCinema(0); output = module.exports.doGetCinema(1); output = module.exports.doGetCinema(2); + output = module.exports.doGetCinema(3); setTimeout(function () { module.exports.preLoad(); @@ -136,8 +141,7 @@ module.exports = { }; setTimeout(function () { - console.log('Pre loading cinemas...'); + logger.debug('Pre loading cinemas...'); module.exports.preLoad(); }, 10000); -