I’ve been fiddeling around and made a Dynamic Tile for Exchange rates and i thought i would share the progress.
It uses the free API of fixer.io. Fixer.io is a free JSON API for current and historical foreign exchange rates published by the European Central Bank.
The rates are updated daily around 3PM CET.
Script:
function exchangerates()
{
var nL = '<linebreak/>';
var base = 'EUR'
var symbol1 = 'RON'
var symbol2 = 'GBP'
var symbol3 = 'HUF'
var u = 'http://api.fixer.io/latest?base='+base+'&symbols='+symbol1+','+symbol2+','+symbol3+'';
var getrates = web.Download(u);
var allrates = JSON.parse(getrates);
var currentdate = allrates.date;
var rate1 = allrates.rates.RON;
var rate2 = allrates.rates.GBP;
var rate3 = allrates.rates.HUF;
return tag.Size(25,'<b><color Blue>Exchange Rates</color></b>') + nL + tag.Size(20,'<b><color Blue>Date: </color></b>') + '<size 20>'+currentdate+'</size>'
+ nL + tag.Size(20,'<color White> '+base+' 1 = '+symbol1+' '+rate1+' </color>')
+ nL + tag.Size(20,'<color White> '+base+' 1 = '+symbol2+' '+rate2+' </color>')
+ nL + tag.Size(20,'<color White> '+base+' 1 = '+symbol3+' '+rate3+' </color>');
}
I know the Script could be better, but hey it’s my first attempt to write something in JScript… and it works
But if anybody would like to re-write the script, be my guest, but be so kind to share again.
The variable base is the currency to which the rates are displayed. The symbol1 to 3 are the currencies for wich the rates will be displayed. The annoying part is i couldn’t figure something out to make the variable rate1 to 3 dynamically dependent on the symbols… so if you want other currencies you will have to update the variables for symbols en those for allrates too (var rate1 = allrates.rates.RON). This definitely could be better.