How can I get Yahoo Weather Backgrounds from API?

2019-07-23 07:00发布

问题:

I have a weather widget, and I need dynamic backgrounds. Yahoo has weather APIs, but I'm not able to find the background image tied to a weather type. https://weather.yahoo.com/ Is this possible?

var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json'
            $.getJSON(url, function (data) {
                console.log(data)
            })

回答1:

The API doesn't provide any images, but you can use a lot of the data to provide an image yourselves. Use for example the following properties

condition":{"code":"34", ...  // here you can bind an image to the code

Then you have a wind object

wind":{
  "chill":"55",       // thermometer?
  "direction":"0",     // use an image or a canvas to draw an arrow dynamically
  "speed":"0"
}, ...

and an atmosphere object

"atmosphere":{
  "humidity":"51",     // some drops?
  "pressure":"30.4",   // textual..
  "rising":"2",
  "visibility":"10"    // textual..
}, ...

And so on. As you can see there are many ways to illustrate these data but it's entirely up to you how to do it.



回答2:

Sorry but there is no API for this. But you can access their backgrounds by viewing the network activity on your browser developer tools.

The best solution is to build your own Api with your own images,

This is a sample of there background url:

https://s.yimg.com/os/mit/media/m/weather/images/fallbacks/lead/clear_n-e618500.jpg