Created
March 27, 2012 20:27
-
-
Save jsulak/2219999 to your computer and use it in GitHub Desktop.
FlightAware FlightXML 2.0 Node.js example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This requires: restler | |
* To install, type 'npm install restler' | |
* Tested with node.js v0.6.14 | |
*/ | |
var util = require('util'); | |
var restclient = require('restler'); | |
var fxml_url = 'http://flightxml.flightaware.com/json/FlightXML2/'; | |
var username = 'YOUR_USERNAME'; | |
var apiKey = 'YOUR_APIKEY'; | |
restclient.get(fxml_url + 'MetarEx', { | |
username: username, | |
password: apiKey, | |
query: {airport: 'KAUS', howMany: 1} | |
}).on('success', function(result, response) { | |
// util.puts(util.inspect(result, true, null)); | |
var entry = result.MetarExResult.metar[0]; | |
util.puts('The temperature at ' + entry.airport + ' is ' + entry.temp_air + 'C'); | |
}); | |
restclient.get(fxml_url + 'Enroute', { | |
username: username, | |
password: apiKey, | |
query: {airport: 'KIAH', howMany: 10, filter: '', offset: 0} | |
}).on('success', function(result, response) { | |
util.puts('Aircraft en route to KIAH:'); | |
//util.puts(util.inspect(result, true, null)); | |
var flights = result.EnrouteResult.enroute; | |
for (i in flights) { | |
var flight = flights[i]; | |
//util.puts(util.inspect(flight)); | |
util.puts(flight.ident + ' (' + flight.aircrafttype + ')\t' + | |
flight.originName + ' (' + flight.origin + ')'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can find an npm package for the FlightAware 2.0 API here ...
https://github.com/icedawn/flightaware.js