Skip to content

Instantly share code, notes, and snippets.

@mmb
Created June 15, 2009 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmb/130397 to your computer and use it in GitHub Desktop.
Save mmb/130397 to your computer and use it in GitHub Desktop.
stock quote
#!/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%">&nbsp;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%">&nbsp;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