0628f3cdc7
Completed weather app, including all updates from Section 9 (Videos 60-69)
18 lines
811 B
JavaScript
18 lines
811 B
JavaScript
const request = require('request')
|
|
|
|
const forecast = (latitude, longitude, callback) => {
|
|
const url = 'https://api.darksky.net/forecast/bae9e39ba5c00299d5a95b35c1ae20cc/' + latitude + ',' + longitude + '?units=si'
|
|
|
|
request({ url, json: true }, (error, {body}) => {
|
|
if (error) {
|
|
callback('Unable to connect to weather service!', undefined)
|
|
} else if (body.error) {
|
|
callback('Unable to find location', undefined)
|
|
} else {
|
|
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. Today\'s high will be ' + body.daily.data[0].temperatureMax + ' degrees, with a low of ' + body.daily.data[0].temperatureMin + '. There is a ' + body.currently.precipProbability + '% chance of rain.')
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = forecast
|