added string and use it to fixe white space and missing .'s

This commit is contained in:
Martin Donnelly 2016-02-15 10:13:54 +00:00
parent f7c331cc78
commit dd55cff45b
2 changed files with 8 additions and 11 deletions

View File

@ -3,7 +3,7 @@
*/ */
var http = require('http'), request = require('request'), cheerio = require('cheerio'), Forecast = require('forecast.io'), util = require('util'), UltraSES = require('ultrases'), cron = require('node-cron'); var http = require('http'), request = require('request'), cheerio = require('cheerio'), Forecast = require('forecast.io'), util = require('util'), UltraSES = require('ultrases'), cron = require('node-cron');
var jade = require('jade'), _ = require('lodash'), dateFormat = require('dateformat'); var jade = require('jade'), _ = require('lodash'), dateFormat = require('dateformat');
var jsonfile = require('jsonfile'), fs = require('fs'); var jsonfile = require('jsonfile'), fs = require('fs'), STRING = require('string');
var log4js = require('log4js'); var log4js = require('log4js');
var logger = log4js.getLogger(); var logger = log4js.getLogger();
@ -134,16 +134,11 @@ module.exports = {
var output = []; var output = [];
tdihbody.find('.tdihevent > p').each(function (div) { tdihbody.find('.tdihevent > p').each(function (div) {
// logger.info($(this));
var s = $(this).text(); var s = $(this).text();
if (s.indexOf('Today\'s recipe:') == -1) { output.push(STRING(s).collapseWhitespace().s);
output.push(s);
}
}); });
todayCache.data.history = todayCache.data.history.concat(output); todayCache.data.history = todayCache.data.history.concat(output);
console.log(todayCache.data.history); console.log(todayCache.data.history);
}); });
}, },
getHistory: function () { getHistory: function () {
@ -258,12 +253,13 @@ module.exports = {
j.later = data.daily.summary; j.later = data.daily.summary;
j.alerts = data.alerts || {}; j.alerts = data.alerts || {};
var fs = STRING(j.currently).endsWith('.') ? '' : '.';
if (tempMax == tempMin) { if (tempMax == tempMin) {
data.currently.summary += '<br/>Around ' + tempMin.toString() + ' degrees.'; j.currently += fs + ' Around ' + tempMin.toString() + ' degrees.';
} }
else else
{ {
data.currently.summary += '<br/>Around ' + tempMin.toString() + ' to ' + tempMax.toString() + ' degrees.'; j.currently += fs + ' Around ' + tempMin.toString() + ' to ' + tempMax.toString() + ' degrees.';
} }
todayCache.data.weather = j; todayCache.data.weather = j;
}); });

View File

@ -20,10 +20,11 @@
"express": "3.x", "express": "3.x",
"node-cron": "^1.0.0", "node-cron": "^1.0.0",
"scrape": "^0.2.3", "scrape": "^0.2.3",
"string": "^3.3.1",
"ultrases": "^0.1.3", "ultrases": "^0.1.3",
"unstyler": "^0.2.2" "unstyler": "^0.2.2"
}, },
"scripts" : { "scripts": {
"start" : "node web-server.js" "start": "node web-server.js"
} }
} }