[ic] {Spam?} Re: Simple Bitcoin exchange rate calculator - UPDATE

Rick Bragg lists at gmnet.net
Thu Sep 15 16:44:53 UTC 2011


Here is an update to the bitcoin exchange rate calculator.  
I made it a bit more accurate, and it now checks to see if the value of
BTC has tanked! ;)

Again it basically just checks the http://bitcoinexchangerate.net
website and returns the value of a given USD in BTC.

Thanks
Rick


# Copyright (C) 2011 by Rick Bragg, Green Mountain Network, www.GreenMountainNetwork.com
#
# Author: Rick Bragg <rbragg at gmnet.net>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# Simple bitcoin exchange rate calculator based on http://bitcoinexchangerate.net.
# Returns the ammount in BTC from USD.  If for some reason the site is down, or the 
# exchange rate has tanked, it will return nothing.
# useage example: [bitcoinexchange usd="100"]
#
# If you like this code, please send a few bit cents to 1DonNZwnRbJmKjZUnSEqLHJFTT2GYRTQ9K

UserTag bitcoinexchange Order usd
UserTag bitcoinexchange addAttr
UserTag bitcoinexchange Routine <<EOR

use WWW::Mechanize;
use Math::Round;

sub {
my ($usd) = @_;
 my $url = 'http://bitcoinexchangerate.net';
 my $browser = WWW::Mechanize->new();

 $browser->get($url);
 if ($browser->success()){
    my $text = $browser->content( format => 'text' );
    my @values = split('USD', $text);
    my $val = @values[0];
    $val =~ s/1 Bitcoin =//;
    $val =~ s/[A-Za-z]//g;
    $val =~ s/ //g;
    if ($val =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ) {
      #It's a number.";
      if ($val > 0){
          #It has not tanked!";
          return nearest (.00000001, ($usd / $val));
      }else{
        return;
      }
    } else {
       return;
    }
  }else{
    return;
 }  
}
EOR









More information about the interchange-users mailing list