Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
XChng v0.1
Morgan "ARR!" Allen <morganrallen@gmail.com>
</morganrallen@gmail.com>
MIT License
usage: node xchng.node.js [ value || 1 ]
*/
var http = require("http"),
sys = require("sys");
for(var i in sys) global[i] = sys[i];
var client = http.createClient(80, "www.ecb.int"),
request = client.request("GET", "/stats/eurofxref/eurofxref-daily.xml", { host: "www.ecb.int" });
var rate = process.argv[2] || 1;
request.on("response", function(response) {
var body = "";
response.on("data", function(chunk) {
body += chunk;
});
response.on("end", function() {
var m, rateMatch = /currency='(.+)' rate='(.+)'/gmi;
while(m = rateMatch.exec(body)) {
puts(rate + "€ = " + (rate * m[2]) + " " + m[1]);
}
});
});
request.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment