Created
September 4, 2011 04:20
-
-
Save IndianGuru/1192249 to your computer and use it in GitHub Desktop.
Accessing Stock quotes
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
require 'open-uri' | |
require 'csv' | |
unless ARGV.length == 1 | |
puts "Usage: jruby09.rb INTC" | |
exit | |
end | |
url = "http://download.finance.yahoo.com/d/quotes.csv?s=#{ARGV[0]}&f=snl1d1t1c1ohgv&e=.csv" | |
csv = CSV.parse(open(url).read) | |
result = Array.new | |
#parse csv data | |
csv.each do |row| | |
result += row | |
end | |
puts "Information current as of " + result[4] + " on " + result[3] | |
puts result[0] +"'s (" + result[1] + ") last trade was - $" + result[2] + " (increase of " + result[5] + ")" | |
puts | |
puts "Opened at $" + result[6] | |
puts "Range for the day $" + result[8] + " - $" + result[7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment