Skip to content

Instantly share code, notes, and snippets.

@ydn
Last active November 19, 2022 15:36
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save ydn/6ef5a695e871b8a628d0 to your computer and use it in GitHub Desktop.
Save ydn/6ef5a695e871b8a628d0 to your computer and use it in GitHub Desktop.
Weather API
var YQL = require('yql');
var query = new YQL('select * from weather.forecast where (location = 94089)');
query.exec(function(err, data) {
var location = data.query.results.channel.location;
var condition = data.query.results.channel.item.condition;
console.log('The current weather in ' + location.city + ', ' + location.region + ' is ' + condition.temp + ' degrees.');
});
<script>
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
alert(wind.chill);
};
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
// Download the following GitHub repository https://github.com/guilhermechapiewski/yql-ios
// Copy the yql-ios folder to your project
#import "YQL.h";
yql = [[YQL alloc] init];
NSString *queryString = @"select wind from weather.forecast where woeid=2460286";
NSDictionary *results = [yql query:queryString];
NSLog(@"%@",results[@"query"][@"count"]);
NSLog(@"%@",results[@"query"][@"results"]);
<?php
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text="chicago, il")';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// Make call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
// Convert JSON to PHP object
$phpObj = json_decode($json);
var_dump($phpObj);
?>
import urllib2, urllib, json
baseurl = "https://query.yahooapis.com/v1/public/yql?"
yql_query = "select wind from weather.forecast where woeid=2460286"
yql_url = baseurl + urllib.urlencode({'q':yql_query}) + "&format=json"
result = urllib2.urlopen(yql_url).read()
data = json.loads(result)
print data['query']['results']
curl https://query.yahooapis.com/v1/public/yql \
-d q="select wind from weather.forecast where woeid=2460286" \
-d format=json
@Bobsilvio
Copy link

How send Celsius in all script?

@savkelita
Copy link

@Bobsilvio
just add inside query u='c';

for example:
'select * from weather.forecast where u='c' AND (location = 94089)'

@s2t2
Copy link

s2t2 commented Jul 22, 2017

For Python 3.x, to get around errors which resulted from the code provided in weather.py:

# Python 2.x
# ...

# Python 3.x
import urllib.parse
import urllib.request
import json

baseurl = "https://query.yahooapis.com/v1/public/yql?"
yql_query = "select wind from weather.forecast where woeid=2460286"
yql_url = baseurl + urllib.parse.urlencode({'q':yql_query}) + "&format=json"
result = urllib.request.urlopen(yql_url).read()
data = json.loads(result)
print data['query']['results']

@S-Keilani
Copy link

Can the forecast language be changed to a language other than English?

@askingokyildiz
Copy link

Can the forecast language be changed to a language other than English?

@cege72
Copy link

cege72 commented Apr 1, 2018

hi !

Im trying to adapt this code for getting sunrise and sunset, using bash
$ l=12776844;curl -s http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{printf("Sunrise: %s, Sunset: %s\n",$2,$4)}'
from linuxquestions forum with new url api , but I don't understand why that doesn't work when expected.

ex for paris:
curl -s https://query.yahooapis.com/v1/public/yql -d q="select astronomy from weather.forecast where woeid=615702" -d format=xml | grep astronomy | awk -F"=" '{printf("sunrise= %s, sunset= %s\n",$6,$7)}'
will return

sunrise= "http://xml.weather.yahoo.com/ns/rss/1.0" sunrise, sunset= "7:27 am" sunset

but not expected

sunrise=7:27 am, sunset=8:22pm

any idea please ?

thank's

@patrickmurphym
Copy link

For Python 3.x, to get around errors which resulted from the code provided in weather.py:

# Python 2.x
# ...

# Python 3.x
import urllib.parse
import urllib.request
import json

baseurl = "https://query.yahooapis.com/v1/public/yql?"
yql_query = "select wind from weather.forecast where woeid=2460286"
yql_url = baseurl + urllib.parse.urlencode({'q':yql_query}) + "&format=json"
result = urllib.request.urlopen(yql_url).read()
data = json.loads(result)
print data['query']['results']

How does the python code change if I use the OAuth credentials? The yahoo developer site doesn't help.

@jainsiddharth21
Copy link

jainsiddharth21 commented Jan 4, 2019

Important EOL Notice: As of Thursday, Jan. 3, 2019, the weather.yahooapis.com and query.yahooapis.com for Yahoo Weather API will be retired.

Does anybody have any idea how to implement it with new way. Documentation is not much clear.

@RadhikaMantri
Copy link

Hi,
I was using this api
http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='location')
but this api in not working any updation or changes in above api.

@hadeedian1
Copy link

https://community.openhab.org/t/solved-yahoo-weather-does-not-work-anymore/62583

Hi,
I was using this api
http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='location')
but this api in not working any updation or changes in above api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment