Created
September 20, 2011 18:19
-
-
Save cronopio/1229855 to your computer and use it in GitHub Desktop.
Playing with currency converter
This file contains 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
var request = require('request'); | |
var csv = require('ya-csv'); | |
var qs = require('querystring'); | |
request('http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDCOP=X', function(err, res, body){ | |
if (err) throw new Error(err); | |
if (!err && res.statusCode == 200){ | |
console.log('Respuesta correcta'); | |
var usd = body.split(','); | |
console.log('Un dolar vale %d pesos colombianos', usd[1]); | |
} | |
}); | |
request('http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=EURCOP=X', function(err, res, body){ | |
if (err) throw new Error(err); | |
if (!err && res.statusCode == 200){ | |
console.log('Respuesta correcta'); | |
var eur = body.split(','); | |
console.log('Un euro vale %d pesos colombianos', eur[1]); | |
} | |
}); | |
request({ | |
method: 'POST', | |
url:'http://alpari-forex.com/es/currency_converter/get_currency/', | |
body:qs.stringify({currency1:'USD',currency2:'COP',line:1,amount:1}), | |
headers:{ | |
"content-type": "application/x-www-form-urlencoded" | |
} | |
}, function(err, res, body){ | |
if (err) throw new Error(err); | |
if (!err && res.statusCode == 200){ | |
var response = JSON.parse(body); | |
console.log('Desde Forex'); | |
console.log('Un dolar son %s',response.res_amount); | |
} | |
}); | |
request({ | |
method: 'POST', | |
url:'http://alpari-forex.com/es/currency_converter/get_currency/', | |
body:qs.stringify({currency1:'EUR',currency2:'COP',line:1,amount:1}), | |
headers:{ | |
"content-type": "application/x-www-form-urlencoded" | |
} | |
}, function(err, res, body){ | |
if (err) throw new Error(err); | |
if (!err && res.statusCode == 200){ | |
var response = JSON.parse(body); | |
console.log('Desde Forex'); | |
console.log('Un Euro son %s',response.res_amount); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment