Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 14, 2012 03:51
Show Gist options
  • Save JGallardo/4282591 to your computer and use it in GitHub Desktop.
Save JGallardo/4282591 to your computer and use it in GitHub Desktop.
Ruby script to retrieve any information from Yahoo Finance.
require 'open-uri'
require 'csv'
def get_info stock_symbol
puts "#{stock_symbol} Current Ticker Information"
url = "http://download.finance.yahoo.com/d/
quotes.csv?s=#{stock_symbol}&f=sl1d1t1c1ohgv&e=.csv"
puts "Connecting to #{url}\n\n\n"
csv = CSV.parse(open(url).read)
csv.each do |row|
puts "--------------------------------------------"
puts "Information current as of #{row[3]} on #{row[2]}\n\n"
puts "#{row[0]}'s last trade was - $#{row[1]} (increase of #{row[4]})\n\n"
puts "\tOpened at $#{row[5]}"
puts "\tRange for the day $#{row[7]} - $#{row[6]}"
end
puts "--------------------------------------------"
end
print "Enter stock symbol (seperate by space if > 1): "
stock_symbols = gets.upcase
stock_symbols.split.each do |symbol|
get_info(symbol)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment