Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - Import data from csv file from url

Tags:

ruby

csv

I am creating a simple app in Ruby on Rails. Need to import data from cvs files at finance.google.com (an example http://www.google.com/finance/historical?q=NYSE:SMH). The program then stores this data for all 500 companies of S&P500 on a daily basis into a database. What's the proper way to do this?

like image 827
user974621 Avatar asked Dec 13 '22 09:12

user974621


1 Answers

Simplest way could be this, it's almost just like reading a file:

require "open-uri"

url = "http://www.google.com/finance/historical?q=NYSE:SMH"
url_data = open(url).read()
# favorite way of parsing csv goes here

EDIT: that was the approach from a script. For a Rails approach you could write a Rake task to do this, and run it periodically via a scheduled task.

like image 103
Geo Avatar answered Dec 15 '22 01:12

Geo