/ Published in: Ruby
Just a quick command-line utility to check inflation values from US statistics office.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'rubygems' require 'net/http' require 'hpricot' if (ARGV.size != 2) puts "usage: inflate.rb original-cost from-year" exit(1) end @original_cost = ARGV[0] @from_year = ARGV[1] @this_year = Date.today.year res = Net::HTTP.post_form(URI.parse("http://data.bls.gov/cgi-bin/cpicalc.pl"), { 'cost1' => @original_cost, 'year1' => @from_year, 'year2' => @this_year, 'submit' => 'Calculate' } ) doc = Hpricot(res.body) puts doc.search("//span[@id='answer']").inner_html