<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  <meta>
    <sampleQuery>select * from aw where airportid="AAXX" and datatype="taf"</sampleQuery>
    <author>Christian Heilmann</author>
    <description>Gets the weather forecast for airports in taf or metar format from http://weather.noaa.gov</description>
  </meta>
  <bindings>
    <select itemPath="" produces="XML">
      <inputs>
        <key id='airportid' type='xs:string' paramType='variable' required="true" />
        <key id='datatype' type='xs:string' paramType='variable' required="false" />
      </inputs>
      <execute><![CDATA[
        if(datatype == 'taf' || datatype == 'metar'){
          var returnobj;
          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';
          }
          var out = y.rest(url).get().response;
          if(out == ''){
            returnobj = <error>Airport {airportid} not found.</error>;
          } else {
            returnobj = <airportweather>{out}</airportweather>;
          }
        } else{
          returnobj = <error>Datatype must be either taf or metar.</error>;
        }
        response.object = returnobj;
      ]]></execute>
    </select>
  </bindings>
</table>

