Fix missing precip data from OpenWeatherMap
This commit is contained in:
@@ -223,34 +223,37 @@ function getOWMWeatherData( location, callback ) {
|
|||||||
|
|
||||||
// Generate URL using The Weather Company API v1 in Imperial units
|
// Generate URL using The Weather Company API v1 in Imperial units
|
||||||
var OWM_API_KEY = process.env.OWM_API_KEY,
|
var OWM_API_KEY = process.env.OWM_API_KEY,
|
||||||
url = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ];
|
currentUrl = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ],
|
||||||
|
forecastUrl = "http://api.openweathermap.org/data/2.5/forecast?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ];
|
||||||
|
|
||||||
// Perform the HTTP request to retrieve the weather data
|
getTimeData( location, function( weather ) {
|
||||||
httpRequest( url, function( data ) {
|
|
||||||
try {
|
// Perform the HTTP request to retrieve the weather data
|
||||||
data = JSON.parse( data );
|
httpRequest( currentUrl, function( data ) {
|
||||||
} catch ( err ) {
|
try {
|
||||||
// Otherwise indicate the request failed
|
data = JSON.parse( data );
|
||||||
callback( false );
|
} catch ( err ) {
|
||||||
}
|
// Otherwise indicate the request failed
|
||||||
|
callback( weather );
|
||||||
|
}
|
||||||
|
|
||||||
getTimeData( location, function( weather ) {
|
|
||||||
weather.temp = parseInt( data.main.temp );
|
weather.temp = parseInt( data.main.temp );
|
||||||
weather.humidity = parseInt( data.main.humidity );
|
weather.humidity = parseInt( data.main.humidity );
|
||||||
weather.wind = parseInt( data.wind.speed );
|
weather.wind = parseInt( data.wind.speed );
|
||||||
|
|
||||||
location = location.join( "," );
|
httpRequest( forecastUrl, function( forecastData ) {
|
||||||
|
try {
|
||||||
|
forecastData = JSON.parse( forecastData );
|
||||||
|
weather.precip = forecastData.list[ 0 ].rain[ "3h" ];
|
||||||
|
callback( weather );
|
||||||
|
} catch ( err ) {
|
||||||
|
|
||||||
getCache( {
|
// Otherwise indicate the request failed
|
||||||
key: "yesterdayHumidity",
|
callback( weather );
|
||||||
location: location,
|
}
|
||||||
weather: weather,
|
|
||||||
callback: callback
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
updateCache( location, weather );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate timezone and sun rise/set information
|
// Calculate timezone and sun rise/set information
|
||||||
|
|||||||
Reference in New Issue
Block a user