• Archives

  • Categories:

Harry Potter and a currency converter, finally!

A friend of mine recently loaned me the first four books of the Harry Potter series. I kept meaning to read them, but was reluctant to buy them when so many people had copies. This friend loaned me the UK Editions. UK Editions? Apparently they’re different, most notably the title of the first is Harry Potter and the Philosopher’s Stone rather than “Sorcerer’s Stone.” So I finished reading the book and couldn’t figure out what they could have changed, plot points? Names? Oh no, they didn’t “translate” it into American English did they?

Yes! They did!

I found this page which describes the differences. I HATE WHEN THEY DO THIS! Now I realize I might speak and understand English English better than your average person because I love britcoms and have lots of brit friends, but this book isn’t hard to read, and most of these British words and terms are easy to figure out (changing room vs locker room, car park vs parking lot, sweets vs candy, dustbin vs trashcan). Why do we need to Americanize everything? Why not expose people to a bit of British culture? You’re reading a book, which means you’re not entirely opposed to putting forth some effort to entertain yourself (rather than just sitting in front of the television). Rawr.

Yesterday I was looking for something to work on, and pulled my IRC Hacks book off the shelf. I had a Hack #55 bookmarked that gave info about how to write a currency converter IRC bot. The problem? The example is in java, so I shelved it until I had time to figure out what they were doing. So yesterday I went to work on it. It used xmethods.net‘s Web Services. What the heck is a Web Service? How would I use it with Perl? I was excited to discover this article that not only explains it, but gives an example of how painfully simple it is with SOAP::Lite.

use SOAP::Lite;

my $result = SOAP::Lite
->service('http://xmethods.net/sd/2001/CurrencyExchangeService.wsdl')
->getRate('us','uk');

print $result;

I say “painfully” simple because I’ve casually been looking for a currency conversion method for R2D2 for over a year. Everyone I’ve talked to about it said their scripts, or ones they know of used xe.com to get the current rates. But as far as I can tell xe.com says “NO NO NO!!!” to automatically leeching their info with scripts, and I don’t want to break TOS with my little bot. But this solution is so simple! And perfect! And why didn’t I know about it before?

<@pleia2onEarth> !convert eur usd
<@R2D2onHour> 1 eur is worth 1.3104 usd

I’ll probably spend some time today editing the script a little so it can do actual currency amounts too.

*wanders off*

EDIT: Well that didn’t take long, I’ve updated the script with the currency amount conversions. Now I can do:

<@pleia2onEarth> !convert 100 usd sek
<@R2D2onHour> 100 usd is worth 692.1200 sek

It still works the old way too.

The whole script can be found on the modular r2d2 page, or by clicking here.