Created
April 10, 2011 21:56
-
-
Save zacclark/912769 to your computer and use it in GitHub Desktop.
An old attempt at getting todays weather data from Wunderground.
This file contains hidden or 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
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