Created
November 10, 2011 05:36
-
-
Save rrguntaka/1354192 to your computer and use it in GitHub Desktop.
Parse Google historical prices csv file
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 "rubygems" | |
require "sequel" | |
require "date" | |
DB = Sequel.connect('jdbc:sqlite:stockinfo.db') | |
DB.create_table? :quote do | |
primary_key :id | |
String :tick | |
DateTime :qdate | |
Float :open | |
Float :high | |
Float :low | |
Float :close | |
Number :volume | |
end | |
quote = DB[:quote] | |
def load_data(tick,table) | |
data = [] | |
File.open(tick + '.csv', 'r') do |f1| | |
line = f1.gets | |
while line = f1.gets | |
temp = line[0..-2].split(',') | |
temp[0] = DateTime.parse(temp[0]) | |
data << temp.unshift(tick.upcase) | |
end | |
end | |
table.import([:tick,:qdate,:open,:high,:low,:close,:volume],data) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment