diff --git a/lib/daily-forecast.js b/lib/daily-forecast.js index a7876b4..7c0896b 100644 --- a/lib/daily-forecast.js +++ b/lib/daily-forecast.js @@ -1,7 +1,7 @@ /** * Daily Forecast * - * - https://weather.com/swagger-docs/ui/sun/v1/sunV1DailyForecast.json + * - https://ibm.co/V3DFap * * The daily forecast API returns the geocode weather forecasts for the current day * up to the days duration in the API endpoint. The daily forecast product can contain @@ -9,37 +9,40 @@ * contain up to (3) “temporal segments” meaning three separate forecasts. For any * given forecast day we offer day, night, and a 24-hour forecast (daily summary). * - * Base URL: api.weather.com/v1 - * Endpoint: /geocode/{latitude}/{longitude}/forecast/daily/{days}day.json + * Base URL: api.weather.com/v3 + * Endpoint: /wx/forecast/daily/15day */ const apiUtil = require('./api-util') -exports.requestOptions = function (lat, lon, days = 3, units = 'm') { - const d = [3, 5, 7, 10, 15].indexOf(days) === -1 ? 3 : days +exports.requestOptions = function (lat, lon, days = 15, units = 'm') { + const d = [3, 5, 7, 10, 15].indexOf(days) === -1 ? 15 : days const u = ['e', 'm', 'h', 's'].indexOf(units) === -1 ? 'm' : units let options = apiUtil.defaultParams() - options['uri'] = `${apiUtil.HOST}/v1/geocode/${lat}/${lon}/forecast/daily/${d}day.json` options.qs['units'] = u + let urlparams="&format=json&units="+options.qs['units']+"&language="+options.qs['language']+"&apiKey="+options.qs['apiKey'] + options['url'] = `${apiUtil.HOST}/v3/wx/forecast/daily/${d}day?geocode=${lat},${lon}`+urlparams + //console.log( options ); return options } exports.handleResponse = function (res) { - if (res && res.hasOwnProperty('forecasts')) { - const forecasts = res.forecasts - console.log(`daily-forecast: returned ${forecasts.length}-day forecast`) + if (res && res.hasOwnProperty('narrative')) { + const forecasts = res + console.log(`daily-forecast: returned ${forecasts.dayOfWeek.length}-day forecast`) - // each entry in the forecasts array corresponds to a daily forecast - forecasts.forEach(daily => { - console.log(`daily-forecast: day ${daily.num} - High of ${daily['max_temp']}, Low of ${daily['min_temp']}`) - console.log(`daily-forecast: day ${daily.num} - ${daily.narrative}`) - }) + // Parse responses + for( num=0; num