2019-08-25 21:16:02 +00:00
const request = require ( 'request' )
const forecast = ( latitude , longitude , callback ) => {
2020-04-13 20:37:50 +00:00
const url = 'http://api.weatherstack.com/current?access_key=360ee65db0f798aa09021f493b5b02c9&query=' + latitude + ',' + longitude + '&units=m'
2019-08-25 21:16:02 +00:00
2019-09-29 18:36:49 +00:00
request ( { url , json : true } , ( error , { body } ) => {
2019-08-25 21:16:02 +00:00
if ( error ) {
callback ( 'Unable to connect to weather service!' , undefined )
2019-09-29 18:36:49 +00:00
} else if ( body . error ) {
2019-08-25 21:16:02 +00:00
callback ( 'Unable to find location' , undefined )
} else {
2020-04-13 20:37:50 +00:00
callback ( undefined , body . current . weather _descriptions [ 0 ] + '. It is currently ' + body . current . temperature + ' degress out. It feels like ' + body . current . feelslike + ' degress.' )
2019-08-25 21:16:02 +00:00
}
} )
}
module . exports = forecast