Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgenica/92396 to your computer and use it in GitHub Desktop.
Save georgenica/92396 to your computer and use it in GitHub Desktop.
#!/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