Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created May 30, 2012 18:20
Show Gist options
  • Save coderforhire/2838102 to your computer and use it in GitHub Desktop.
Save coderforhire/2838102 to your computer and use it in GitHub Desktop.
desc "Fetch stocks"
task :fetch_stocks => :environment do
require 'nokogiri'
require 'open-uri'
require 'pp'
@stocks = Stock.all
@stocks.each do |stock|
url = "ymbols=#{stock.ticker}"
doc = Nokogiri::XML(open(url))
data = Hash.from_xml(doc.to_s)
puts stock.ticker
puts data
puts #{data['FinancialData' => 'Quote' => company_name]}
stock.update_attributes(data["FinancialData"]["Quote"])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment