Javascript Airport weather decoder
While weatherpixie remains on extended hiatus, I have finally put together a simple in-browser replacement. It uses James Padolsey's cross-domain Ajax plug-in for jQuery (indirecting via YQL), a simple parsing script from Manuel Heras, here separated into a stand-alone script, and an iframe
-based page to do the work.
The final piece of heavy lifting is to get the appropriate METAR report for the local airfield, and that's just a few lines of javascript --
$(document).ready(function(){ | |
var lmurl = "http://weather.noaa.gov/mgetmetar.php?cccc=EGSC&Submit=SUBMIT" | |
$.get(lmurl, function(res) { | |
$(res.responseText).find('hr + p').each(function(i, a) { | |
var text = a.innerText; | |
if (text == undefined) text = a.textContent; | |
text = do_metar(text); | |
while (text.indexOf('\n') >= 0) | |
text = text.replace('\n', '< br />'); | |
$('#report').html(text); | |
}); | |
}); | |
}); |
Here, EGSC is the ICAO code for Cambridge Airport. And that's a lot closer to home than the Met. Office who give out current conditions at Bedford on the Cambridge forecast!
No comments :
Post a Comment