Majestic Sea Creature

Technical Ramblings from Gregory Brown (@seacreature)

A Trivial Dow Jones Ticker

I normally use Mechanize for screen scraping, but sometimes, you don’t need more than open-uri and a quick regex. My political views aside, here’s a tiny script to pull whatever the current bad dream is on the Dow. Turn it on while you watch bad news on TV for interactive fun.

require "open-uri"
loop do
  puts( open("http://finance.google.com/finance?cid=983582").read[
  /<span class="\w+" id="ref_983582_c">([+-]?\d+\.\d+)/m, 1] )
  sleep(10)
end

You may want to put a much, much less aggressive polling time in there, on the order of a few minutes. But what can I say, I’m impatient. Enjoy!

UPDATE: adjustments made to generalize match a bit

Written by Gregory Brown on 2008.10.02 at 14:33 | Responses


blog.majesticseacreature.com : Home | Archives | Feed