Skip to content

Instantly share code, notes, and snippets.

@astro313
Created October 21, 2017 17:33
Show Gist options
  • Save astro313/16d98e95a307957ef46d78dd8655460e to your computer and use it in GitHub Desktop.
Save astro313/16d98e95a307957ef46d78dd8655460e to your computer and use it in GitHub Desktop.
Get latest stock price using Ruby, enter symbol as argument
'''
from https://gist.github.com/IndianGuru/1192249
Working, as of 21 Oct 2017
'''
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