Skip to content

Instantly share code, notes, and snippets.

@rrguntaka
Created November 10, 2011 05:36
Show Gist options
  • Save rrguntaka/1354192 to your computer and use it in GitHub Desktop.
Save rrguntaka/1354192 to your computer and use it in GitHub Desktop.
Parse Google historical prices csv file
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