Finance Currency Convert

by GarciaPL on Tuesday 17 February 2015

After my last trip do Budapest with my wife (I really recommend going to this town! It's wonderful! not only building, but also people are very very nice to tourists), I had a little forints. There is not such much of them, but recently I was checking what is the current currency rate of forint to exchange those money. It was no such difficult to do it, I just did request to Google like '9000 HUF to PLN'. Then idea came to me, that I can wrote some script in Perl which can do it for me and additionally inform via email when there is a good opportunity to exchange those money.

For sending emails I used very nice API called Mandrill [2]. For currency convert from HUF to PLN I used module called Finance::Currency::Convert::Yahoo [3].

#!/usr/bin/perl -w
use strict;
use POSIX;
use WebService::Mandrill;
use Finance::Currency::Convert::Yahoo;
 
$Finance::Currency::Convert::Yahoo::CHAT = 1;
$_ = Finance::Currency::Convert::Yahoo::convert(9430,'HUF','PLN');
 
if (defined($_)) {
   if (floor($_) gt 135) {
      print "Sell HUF : ".floor($_)."\n";
      send_email('receiver@gmail.com', 'Sell HUF', 'Right now there is the time to sell HUF');
   } else {
      print "Keep HUF\n";
   }
} else {
   print "Error\n";  
}
 
sub send_email {
 
        (my $to, my $subject, my $body) = @_;
 
        my $mandrill = WebService::Mandrill->new(
                debug   => 1,
                api_key => 'YOUR_API_TO_MANDRILL',
        );
 
        my $response = $mandrill->send(
                subject      => $subject,
                from_email   => "sender\@gmail.com",
                text         => $body,
                track_opens  => 1,
                track_clicks => 1,
                to => [
                    { email => $to }
                ],
        );
}




Reference : [1] Pastebin Source Code Finance Current Convert [2] Mandrill.com [3] CPAN Finance::Currency::Convert::Yahoo