Skip to content

Instantly share code, notes, and snippets.

@zacclark
Created April 10, 2011 21:56
Show Gist options
  • Save zacclark/912769 to your computer and use it in GitHub Desktop.
Save zacclark/912769 to your computer and use it in GitHub Desktop.
An old attempt at getting todays weather data from Wunderground.
require "rexml/document"
# http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=Boulder,CO
require 'net/http'
Net::HTTP.start("api.wunderground.com") do |http|
resp = http.get("/auto/wui/geo/ForecastXML/index.xml?query=Boulder,CO")
open("weather.xml", "wb") do |file|
file.write(resp.body)
end
end
puts "Done."
file = File.new( "./weather.xml" )
doc = REXML::Document.new file
high = doc.root.elements[3][1].elements["high"].elements["fahrenheit"].text
low = doc.root.elements[3][1].elements["low"].elements["fahrenheit"].text
file.close
puts high
puts low
out = File.new("./output/today.json", 'w')
out.write("{")
out.write("\"high\": #{high},\"low\": #{low}")
out.write("}")
out.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment