Video 37
This commit is contained in:
17
weather-app/utils/forecast.js
Normal file
17
weather-app/utils/forecast.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const request = require('request')
|
||||
|
||||
const forecast = (latitude, longitude, callback) => {
|
||||
const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si'
|
||||
|
||||
request({ url: url, json: true }, (error, response) => {
|
||||
if (error) {
|
||||
callback('Unable to connect to weather service!', undefined)
|
||||
} else if (response.body.error) {
|
||||
callback('Unable to find location', undefined)
|
||||
} else {
|
||||
callback(undefined, response.body.daily.data[0].summary + ' It is currently ' + response.body.currently.temperature + ' degrees out. There is a ' + response.body.currently.precipProbability + '% chance of rain.')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = forecast
|
||||
Reference in New Issue
Block a user