Created
April 15, 2011 09:33
-
-
Save davide-romanini/921464 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
importPackage(Packages.java.net); | |
importPackage(Packages.org.w3c.tidy); | |
var Euribor = function() { | |
var tidy = new Tidy(); | |
tidy.XHTML = true; | |
tidy.fixComments = true; | |
tidy.trimEmptyElements = true; | |
tidy.onlyErrors = true; | |
tidy.showWarnings = false; | |
tidy.quiet = true; | |
return { | |
data: {}, | |
get: function(year, month, type) { | |
if(this.data[year] == undefined) { | |
this.data[year] = {}; | |
var input = new URL('http://euribor.it/storico_mensile.php?anno=' + year).openStream(); | |
var dom = tidy.parseDOM(input, null); | |
var x = new XML(dom); | |
var rows = x..table.(@id=='euribor mensile')..tr; | |
for(i = 0; i < rows.length(); i++) { | |
var tr = rows[i]; | |
if(i > 0) { | |
this.data[year][i] = {}; | |
this.data[year][i][1] = parseFloat(tr.td[1].toString().replace(',','.')); | |
this.data[year][i][3] = parseFloat(tr.td[2].toString().replace(',','.')); | |
this.data[year][i][6] = parseFloat(tr.td[3].toString().replace(',','.')); | |
} | |
} | |
} | |
return this.data[year][month][type]; | |
} | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment