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