Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created July 4, 2012 08:00
Show Gist options
  • Save dpaluy/3046002 to your computer and use it in GitHub Desktop.
Save dpaluy/3046002 to your computer and use it in GitHub Desktop.
Download 12 years stock history data from: http://markets.chron.com/chron/markets
require 'fileutils'
require 'open-uri'
class Chron
def initialize(symbol)
@symbol = symbol
end
def grab_year(year)
url = "http://markets.chron.com/chron/action/gethistoricaldata?Month=12&Symbol=#{@symbol}&Range=12&Year=#{year}"
open("#{@symbol}/#{@symbol}_#{year}.csv", 'w') do |file|
file << open(url).read
end
puts "Downloaded: #{@symbol}_#{year}.csv"
end
def grab_data
(0..12).each do |y|
grab_year(y.to_s.rjust(2, '0'))
end
end
end
##############
# MAIN #
##############
if ARGV.length() < 1
puts "Usage: " + __FILE__ + " symbol"
exit
end
symbol = ARGV[0]
FileUtils.mkdir symbol
chron = Chron.new(symbol)
chron.grab_data
puts "Completed: #{symbol}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment