From a1486b91e0da31e96460199f065e376cdb511d06 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Fri, 1 Mar 2019 13:45:11 -0600 Subject: [PATCH] Add forecast data --- routes/weather.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 275d63a..bbbb451 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -63,12 +63,25 @@ function getOWMWeatherData( location, callback ) { weather.humidity = 0; weather.wind = 0; weather.precip = 0; + weather.forecast = []; - for ( var index = 0; index < maxCount; index++ ) { - weather.temp += parseInt( data.list[ index ].main.temp ); - weather.humidity += parseInt( data.list[ index ].main.humidity ); - weather.wind += parseInt( data.list[ index ].wind.speed ); - weather.precip += data.list[ index ].rain ? parseFloat( data.list[ index ].rain[ "3h" ] || 0 ) : 0; + for ( var index = 0; index < data.list.length; index++ ) { + if ( index < maxCount ) { + weather.temp += parseInt( data.list[ index ].main.temp ); + weather.humidity += parseInt( data.list[ index ].main.humidity ); + weather.wind += parseInt( data.list[ index ].wind.speed ); + weather.precip += data.list[ index ].rain ? parseFloat( data.list[ index ].rain[ "3h" ] || 0 ) : 0; + } + + if ( index % 8 === 0 ) { + weather.forecast.push( { + temp_min: parseInt( data.list[ index ].main.temp_min ), + temp_max: parseInt( data.list[ index ].main.temp_max ), + date: parseInt( data.list[ index ].dt ), + icon: data.list[ index ].weather[ 0 ].icon, + description: data.list[0].weather[ 0 ].description + } ); + } } weather.temp = weather.temp / maxCount;