From dd55cff45bfc56845adceef064608ca8165c09e4 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Mon, 15 Feb 2016 10:13:54 +0000 Subject: [PATCH] added string and use it to fixe white space and missing .'s --- lib/today.js | 14 +++++--------- package.json | 5 +++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/today.js b/lib/today.js index 81b574e..573152f 100644 --- a/lib/today.js +++ b/lib/today.js @@ -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 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 logger = log4js.getLogger(); @@ -134,16 +134,11 @@ module.exports = { var output = []; tdihbody.find('.tdihevent > p').each(function (div) { - - // logger.info($(this)); var s = $(this).text(); - if (s.indexOf('Today\'s recipe:') == -1) { - output.push(s); - } + output.push(STRING(s).collapseWhitespace().s); }); todayCache.data.history = todayCache.data.history.concat(output); console.log(todayCache.data.history); - }); }, getHistory: function () { @@ -258,12 +253,13 @@ module.exports = { j.later = data.daily.summary; j.alerts = data.alerts || {}; + var fs = STRING(j.currently).endsWith('.') ? '' : '.'; if (tempMax == tempMin) { - data.currently.summary += '
Around ' + tempMin.toString() + ' degrees.'; + j.currently += fs + ' Around ' + tempMin.toString() + ' degrees.'; } else { - data.currently.summary += '
Around ' + tempMin.toString() + ' to ' + tempMax.toString() + ' degrees.'; + j.currently += fs + ' Around ' + tempMin.toString() + ' to ' + tempMax.toString() + ' degrees.'; } todayCache.data.weather = j; }); diff --git a/package.json b/package.json index 414d58c..967bcdc 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,11 @@ "express": "3.x", "node-cron": "^1.0.0", "scrape": "^0.2.3", + "string": "^3.3.1", "ultrases": "^0.1.3", "unstyler": "^0.2.2" }, - "scripts" : { - "start" : "node web-server.js" + "scripts": { + "start": "node web-server.js" } }