Return Yahoo! weather API data in Celsius, using YQL

帅比萌擦擦* 提交于 2019-12-03 10:58:28

Better late than never...

var locationQuery = escape("select item from weather.forecast where woeid in (select woeid from geo.places where text='GB-LND') and u='c'"),
    locationUrl = "http://query.yahooapis.com/v1/public/yql?q=" + locationQuery + "&format=json&callback=?";

It's easier to read if you break it up. You we're pretty close, just needed the u=c as part of the query, not at the end of the url.

I used the yql

select item from weather.forecast where woeid=22724447 and u='c'

and it worked fine with the results in Celsius. I changed the "LEXX0003" for the real WOEID of that zone and it seems to have worked.

Whenever I had to call a temperature that I wanted in Celsius I just used a simple conversion function:

function FtoC(temp) {return Math.round((temp - 32) / (9 / 5));}

Then again, I wanted to toggle between Fahrenheit and Celsius. Just calling the Celsius JSON element from Yahoo is probably better if all you want to use is Celsius.

You can try this:

YQL Query:

select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="jiangmen,cn") and u="c"

EndPoint:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22jiangmen%2Ccn%22)%20and%20u%3D%22c%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

This work when I try just now

user10002267

just do this,be sure it will work

add this -->{ and u="c" } at the end of the YQL Query

for example:

YQL Query

select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="greenland") and u="c"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!