Christian Heilmann

Turning a web folder with data into an API using YQL execute

Monday, November 30th, 2009 at 1:00 pm

Yesterday Johan Bouveng challenged me on Facebook with another brain teaser. Johan had found a nice resource for weather forecasts for airports. The data came back in TAF or METAR formats and he already had a parser for this (thank f*** – what a mess these formats). Now, what he wanted to have is an API to get the weather forecast data from the following resources:

Using YQL and YQL execute this was pretty easy. All I had to do was to write an open table that reads the correct file.

// check if taf or metar was requested or return an error
if(datatype 'taf' || datatype ‘metar’){
var returnobj,url;

// get the correct url using the airport ID and format
if(datatype==’metar’){
url = ‘http://weather.noaa.gov/pub/data/observations/’ +
‘metar/stations/’ + airportid + ‘.TXT’
} else {
url = ‘http://weather.noaa.gov/pub/data/forecasts/’+
‘taf/stations/’ + airportid +’.TXT’;
}

// do a REST call and get the response back
var out = y.rest(url).get().response;

// if there is no data returned, return an error.
if(out == ‘’){
returnobj = Airport {airportid} not found.;

// otherwise return the data in the TXT file
} else {
returnobj = {out};
}

} else{
// error condition for wrong datatype
returnobj = Datatype must be either taf or metar.;
}

// give back the data to YQL
response.object = returnobj;

Having done this you can now use it as a table in YQL:

use “http://isithackday.com/hacks/airportweather/airportweather.xml” as aw;
select * from aw where airportid=”AAXX” and datatype=”taf”;

As you can see, you don’t have to be a genius to build your own API :)

Tags: , , , , ,

Share on Mastodon (needs instance)

Share on BlueSky

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

160: Graphs and RAGs explained and VS Code extension hacks Graphs and RAG explained, how AI is reshaping UI and work, how to efficiently use Cursor, VS Code extensions security issues.
159: AI pipelines, 10x faster TypeScript, How to interview How to use LLMs to help you write code and how much electricity does that use? Is your API secure? 10x faster TypeScript thanks to Go!
158: 🕹️ Super Mario AI 🔑 API keys in LLMs 🤙🏾 Vibe Coding Why is AI playing Super Mario? How is hallucinating the least of our worries and what are rules for developing Safety Critical Code?
157: CUDA in Python, Gemini Code Assist and back-dooring LLMs We met with a CUDA expert from NVIDIA about the future of hardware, we look at how AI fails and how to play pong on 140 browser tabs.
156: Enterprise dead, all about Bluesky and React moves on! Learn about Bluesky as a platform, how to build a React App and how to speed up SQL. And play an impossible game in the browser.

My other work: