Created
April 9, 2009 11:13
-
-
Save georgenica/92396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
URL="http://www.bnro.ro/nbrfxrates.xml" | |
OUTPUT_DIR="/home/grn/invoicer/currencies" | |
%w[rubygems net/http].each { |x| require x } | |
gem 'hpricot', '>= 0.6' | |
require 'hpricot' | |
today = Time.new.strftime('%Y%m%d') | |
f = File.open("#{OUTPUT_DIR}/#{today}", "w") | |
begin | |
xml = Net::HTTP.get URI.parse(URL) | |
rescue | |
puts "Error downloading XML file!" | |
exit | |
end | |
puts "Today's exchange rates :\n\n" | |
doc = Hpricot::XML(xml) | |
(doc/:Rate).each do |c| | |
ca = c.attributes["currency"] | |
if ca == "USD" || ca == "EUR" then | |
f.write "#{ca}:#{c.innerHTML}\n" | |
puts "#{ca}:#{c.innerHTML}\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment