There are many situations when I need to convert an amount of Euros to RON (Romanian Leu). There are a couple of sites that can do the conversion for you (even Google does this pretty well). However, none of them seem to be as accurate as the the National Bank of Romania, whose exchange rate is the only one that has any relevance for me. So most of the times I have to open the calculator, go the BNR website and use the exchange rate provided here, an issue that doesn’t work very well for a lazy ass like me.
Fortunately, BNR also provides an XML with the exchange rates for the most important currencies in a manner that is very easy to understand:
...
<Rate currency="DKK">0.4926</Rate>
<Rate currency="EGP">0.4291</Rate>
<Rate currency="EUR">3.6747</Rate>
<Rate currency="GBP">4.6020</Rate>
...
Luckily, Perl knows how to parse XMLs so we’re almost good to go. Now I am not Perl expert, nor want to become one very soon, but this sounded like something doable with a minimum amount effort.
What we need is to get the XML with an HTTP request, parse it and convert the given amount of money using the desired currency. So I created a tiny script convert2ron.pl that accepts two parameters: the currency identifier (EUR, USD, etc.) and the amount to be converted. I will not go into the details of how this script works as it’s pretty straight-forward (even for someone with a minimal understanding of Perl). So now I can convert all sorts of currencies to RON using calls like this:
$ ./convert2ron.pl EUR 245
and get results like these:
245 EUR = 900.30 RON
(rate is 3.6747)
Is this the geekiest way to do this, or what? And the geekness doesn’t stop here. Now I also have some scripts like eur2ron.sh and usd2ron.sh so I can do stuff like this all day:
$ eur2ron 456
So, if you want to convert international currencies to RON the geek way, here’s the download: http://cosminaru.ro/downloads/ron-convert.zip.
7 comments ↓
FUCK! I parsed their HTML code with regular expressions. FUCK! The idiot that I am!
FUCK!
And when you think that I thought of my self as the only geek to do this. Pfiuuu
salut, daca ai IPhone, iti recomand http://ichange.ro/
e bazat tot pe xml-ul de la BNR.
[...] My Perl knowledge is minimal, but I sometimes use it to automate some of my shit. Some of my geekiest stuff can help you make and idea about what Perl can be used for in the tooling arena: * http://cosminaru.ro/blog/2009/01/28/more-perl-geekness-getting-the-class-bytecode-version/ * http://cosminaru.ro/blog/2008/04/09/currency-conversions-the-geek-way/ [...]
{Simply|Just} {want to|wish to|desire to} say your article is as {astonishing|amazing|surprising|astounding}. The {clearness|clarity} in your post is {simply|just} {spectacular|nice|excellent|cool|great} and i {can|could} assume {you are|you’re} an …
Act as if what you do makes a difference. It does…
The invisible hand of the market always moves faster and better than the heavy hand of government….
It’s perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I desire to suggest you few interesting things or advice. Maybe you could write next articles referring to this article. I want to rea…
Leave a Comment