Skip to content

Instantly share code, notes, and snippets.

@morganrallen
Created September 3, 2010 13:07
Show Gist options
  • Save morganrallen/563851 to your computer and use it in GitHub Desktop.
Save morganrallen/563851 to your computer and use it in GitHub Desktop.
/*
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