YQL Open Table Design

use “http://github.com/vicmortelmans/yql-tables/raw/master/weather/weather.frost.xml”  as weather.frost;select * from weather.frost where location = “Ringsaker”

(note: this location is somewhere in northern Scandinavia, where it’s more likely to freeze :)

Google Weather API

Google’s secret weather API:


YQL Open Table Execute

var url = “http://www.google.com/ig/api?weather=$location“;
url = url.replace(/\$location/,encode-uri(location));
xml = y.query(“select * from xml where url=’http://www.google.com/ig/api?weather=antwerpen‘”).results;
var seq = new String();
for each (var lowtemp in xml..forecast_conditions.low.@data) {
seq += (lowtemp > 32 ? ‘+’ : ‘-’);
seq = seq.substr(0,3);
var output = new String();
switch (seq) {
case “+++”:
output = “Aanhoudende dooi in $location”;
case “++-”:
output = “Overmorgen gaat het vriezen in $location”;
case “+-+”:
case “+–”:
output = “Morgen gaat het vriezen in $location”;
case “—”:
case “-+-”:
case “–+”:
output = “Aanhoudende vorst in $location”;
case “-++”:
output = “Morgen dooit het in $location”;
output = output.replace(/\$location/,location);

YQL XML open table returns no data when strange characters are in the XML

When running a query on the Google weather API for a city in France, very often the returned XML contains strange characters, like e.g. in “Avignon, Provence-Alpes-Côte d’Azur”. When querying for this xml through YQL XML open table, nothing is returned!

The Google API is not providing encoding information:

<?xml version=”1.0″?>

Based on an octal dump, I’d say it’s UTF8:

0000300   s   -   C 303 264 t   e       d   &   #   3   9   ;   A   z

Yahoo weather YQL tables

select * from weather.woeid where w in (select woeid from geo.places where text=”paris”)

Not very useful… only one day forecast, and e.g. for ‘Paris’ returning all cities with the name.

Creating a pipe works better:


The pipe first gets the woeid for the location using the YQL woeid open table (see above), then loads the weather info from the Yahoo Weather RSS feed.

The result is formatted html, so extracting the low temp values requires text parsing.

World Weather Online API

Registration required, a simple API, but it won’t take ‘Antwerpen’, but only the english name of this flemish city… not so nice!


So let’s use the YQL geo.places open table for getting the coordinates of our location, and feed this to the longitude/latitude World Weather Online API:


This operation chain is performed in this pipe.

This pipe, on it’s turn, can be used as source for YQL open table execute scripting, via the JSON open table query:

select * from json where url=”http://pipes.yahoo.com/pipes/pipe.run?_id=70a400f5404b6a454caf850de3f62d33&_render=json&location=paris” and itemPath=”//tempMinC”

The final weather.frost open table allows for an extra parameter: the target language.

use “http://github.com/vicmortelmans/yql-tables/raw/master/weather/weather.frost.xml”  as weather.frost;select * from weather.frost where location = “Antwerpen” and language=”nl”

Yahoo Pipe

The wrapper pipe is needed to turn the YQL query output into RSS format.







It would be nice if the language could be automatically detected, based on the provided city name! (but what about Brussels?).

Google Gadget

The original Frost Alert article refers to the Google Webpage where the Google gadget is published.

Managing the site is done in sites.google.com, but that’s OK.

Editing the gadget is done in the iGoogle Gadget Editor. This is the gadget code:

<?xml version=”1.0″ encoding=”UTF-8″?>
<ModulePrefs title=”Vorstalarm!” height=”401″ width=”576″ author=”Vic Mortelmans” author_email=”vic.mortelmans@telenet.be”/>
<Content type=”html”><![CDATA[
<script type="text/javascript">
htmlTemplate = '<a href="http://www.addtoany.com/subscribe?linkname=Vorstalarm!&amp;linkurl=http%3A%2F%2Fpipes.yahoo.com%2Fpipes%2Fpipe.run%3F_id%3D145e579bd145fb0b01f9473f69b7e4c1%26_render%3Drss%26language%3Dnl%26location%3D_LOCATION_" target="_blank"><img src="http://static.addtoany.com/buttons/subscribe_120_16.gif" width="120" height="16" border="0" alt="Subscribe"/></a>';
function displayGetRSS () {
var html = htmlTemplate.replace(/_LOCATION_/,document.getElementById('input').value);
document.getElementById('content_div').innerHTML = html;
<img src="http://farm4.static.flickr.com/3520/4058180670_ed979a4099_o.jpg" width="576" height="401" alt="breughel_hunters" />
<div style="position: relative; background: white; top: -350px; left: 193px; width: 190px; height: 110px; padding: 10px" >
<div style="text-align: center">
<input id="input" name="location" onkeyup="displayGetRSS()" type="text"/>
<div id="content_div" style="text-align: center">
<img src="http://static.addtoany.com/buttons/subscribe_120_16.gif" width="120" height="16" border="0" alt="Subscribe"/>

Note that it seems the gagdet must be published (and re-inserted into the webpage) before changes take effect !?

About these ads

One thought on “Vorstalarm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s