Created
July 4, 2012 08:00
-
-
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
This file contains hidden or 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 '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