/** * Created by Martin on 31/03/2016. */ const Forecast = require('forecast.io'); const STRING = require('string'); const logger = require('log4js').getLogger('weather'); const forecastOptions = { 'APIKey': '9ad2a41d420f3cf4960571bb886f710c', 'units': 'uk2' }; module.exports = { 'newDoGetWeather': function() { 'use strict'; return new Promise(function(resolve, reject) { logger.info('New Retrieving weather..'); const j = {}; const forecast = new Forecast(forecastOptions); forecast.get(55.95, -4.566667, { 'units': 'uk2' }, function(err, res, data) { if (err) return reject(err); const tempMin = parseInt(data.daily.data[0].temperatureMin); const tempMax = parseInt(data.daily.data[0].temperatureMax); j.currently = data.currently.summary; j.today = data.daily.data[0].summary; j.later = data.daily.summary; j.alerts = data.alerts || {}; j.data = data; const fs = STRING(j.currently).endsWith('.') ? '' : '.'; if (tempMax === tempMin) j.currently += `${fs } Around ${ tempMin.toString() } degrees.`; else j.currently += `${fs } Around ${ tempMin.toString() } to ${ tempMax.toString() } degrees.`; // logger.debug(j); return resolve(j); }); }); } };