3

I'm trying to find a way to get some weather information with Yahoo Weather using Yahoo Query Language.

As I'm living in France, in a city called Nice, the following query returns an error:

select * from weather.forecast where location='Nice'

I have the latitude and longitude coordinated, so how can I give them to YQL to return the weather info? Is this service worldwide or just for the US?

Laurel
  • 5,965
  • 14
  • 31
  • 57
Zakaria
  • 14,892
  • 22
  • 84
  • 125

1 Answers1

4

You should use another YQL datatable instead. I have tried this query and it works fine:

SELECT * FROM weather.bylocation WHERE location='Nice' AND unit="c"

This is the YQL console

I have added unit="c" to get it it Celsius, assuming that you want that. If not, use "f".

Internally the weather.bylocation table is using the following two things:

  1. Lookup of the 'where on earth identifier (woeid) for the location,
  2. and then lookup of the weather for this id.

See the internals of that table below:

    <execute><![CDATA[
      default xml namespace ='http://where.yahooapis.com/v1/schema.rng'; 
      var x = y.query('select woeid from geo.places(1) where text="'+location+'"');
      var s = x.results;
      var woeid = s..woeid;
      var weather = y.rest('http://weather.yahooapis.com/forecastrss?w='+woeid+'&u='+unit).get().response;
      response.object = <weather>{weather}</weather>;
    ]]></execute>

Regarding your 2nd question about usage of latitude and longitude coordinated: I don't know if you can use them but maybe you don't even need this anymore now, right?

Also good read:

http://developer.yahoo.com/weather/

http://developer.yahoo.com/geo/geoplanet/guide/concepts.html

Laurel
  • 5,965
  • 14
  • 31
  • 57
spier
  • 2,642
  • 1
  • 19
  • 16
  • if you want to change unit to Celsius when you use weather.forecast table, you need to add this condition with AND operator: u="c" i.e.: select * from weather.forecast where woeid=823015 and u="c" – golddragon007 Feb 08 '16 at 14:36
  • This query no longer works. Getting this error: `Please provide valid credentials`. It appears YQL is becoming less and less reliable as websites either block the user agent or require OAuth. – thdoan Aug 26 '16 at 04:10