Skip to content

Instantly share code, notes, and snippets.

@samuelhei
Created October 20, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelhei/624f63fb08897c6e035a to your computer and use it in GitHub Desktop.
Save samuelhei/624f63fb08897c6e035a to your computer and use it in GitHub Desktop.
//Required library request (npm i request --save)
var getUSDBRL = function(callback) {
var request = require('request');
var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22USDBRL%22&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var usdbrl = JSON.parse(body).query.results.rate.Rate;
callback(usdbrl);
} else {
console.log("Got an error: ", error, ", status code: ", response.statusCode);
}
});
};
getUSDBRL(function(usdbrl){
console.log(usdbrl);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment