Created
June 15, 2009 22:42
-
-
Save mmb/130397 to your computer and use it in GitHub Desktop.
stock quote
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
#!/usr/bin/ruby | |
require 'open-uri' | |
require 'hpricot' | |
symbol = ARGV[0] | |
open("http://www.nasdaq.com/aspxcontent/NasdaqRSS.aspx?data=quotes&symbol=#{symbol}") do |f| | |
doc = Hpricot(f) | |
desc = (doc/"//rss/channel/item/description").first.inner_html | |
last = desc.match(/<TD nowrap width="50%"> Last\s*<\/TD>\s*<TD nowrap align=right width="50%">(\d+\.\d\d)\s*<\/TD>/)[1].to_f | |
change_dir, change = desc.match(/<TD nowrap width="50%"> Change\s*<\/TD>\s*<TD nowrap align=right width="50%"><font.*?>([-\+])<img src=.*?\s*>(\d+\.\d\d)<\/font>/)[1,2] | |
puts "#{last} (#{change_dir}#{change})" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment