I'm using yahoo weather api for get weather feed of single city, now I want to get weather feed for multiple cities in single request, how can I do using yahoo api. I also want to know, is ther any api yahoo provides to get the list of city of any country.
My weather.js
import OAuth from 'oauth';
const header = {
"X-Yahoo-App-Id": "myappid"
};
const request = new OAuth.OAuth(
null,
null,
'myconsumerkey',
'myconsumersecret',
'1.0',
null,
'HMAC-SHA1',
null,
header
);
request.get('https://weather-ydn-yql.media.yahoo.com/forecastrss?w=713169&format=json', null,null, function (err, data, result) {
if (err) {
console.log(err);
} else {
console.log(data)
}
});
Using this code i can be able to get weather details for only one city i want to fetch weather details for multiple cities at once.
thanx in advance!!
So reading the documentation it doesn't seem possible to send a batch of locations to the Yahoo Weather API. But what you can do is
.map()over an array of locations and make multiple requests.https://developer.yahoo.com/weather/documentation.html#params
Since OAuth 1.0 is a callback, I've wrapped that with a
new Promise(), which will give us an array of unfulfilled promises. Then finally,Promise.all()method returns a single Promise that fulfills when all of the promises passed as an iterable have been fulfilled.I have tested this with the API and here is an example response for the code above.