Skip to content

Instantly share code, notes, and snippets.

@danneu
Created December 3, 2011 22:38
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 danneu/1428374 to your computer and use it in GitHub Desktop.
Save danneu/1428374 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
zipcode = ARGV[0] || 78705
url = "http://www.weather.com/weather/hourbyhour/graph/#{zipcode}"
doc = Nokogiri::HTML(open(url))
raise('Zipcode not found') if /can't find the page you requested/ =~ doc.text
hours = doc.css('.hbhWxHour')
hours.each do |hour|
time = hour.css('.hbhWxTime').text
temp = hour.css('.hbhWxTemp').text
precip = /\d*[%]/.match hour.css('.hbhWxPrecip').text
puts "%5s: %6s (%s)\n" % [time, temp, precip]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment