Posted By

plexus on 04/14/08


Tagged

ruby convert currency Hpricot xurrency


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

georg
sergeizen
webstic


Command line Currency converter


 / Published in: Ruby
 

URL: http://www.arnebrasseur.net

Command line currency convertor, just copy and paste. I named mine 'coin'. Make sure you have Ruby, Rubygems and Hpricot (gem install hpricot).

e.g. ~$ coin 100 eur usd 158.3300

Uses the site xurrency.com.

  1. #!/usr/bin/env ruby -w
  2.  
  3. unless ARGV.length == 3
  4. puts "\tUsage :\n\t\t#{File.basename($0)} 100 eur usd"
  5. exit
  6. end
  7.  
  8. require 'ubygems'
  9. require 'open-uri'
  10. require 'hpricot'
  11.  
  12. url = "http://xurrency.com/#{ARGV.join('/')}/feed"
  13. doc=Hpricot(open(url).read)
  14.  
  15. puts (doc/'dc:value').inner_html

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: plexus on October 20, 2009

The API changed so this no longer works.

Posted By: plexus on October 20, 2009

Note that Google can do this, e.g. type "100 EUR in USD" in the search box.

You need to login to post a comment.