Created
July 9, 2012 18:03
-
-
Save dylanj/3077921 to your computer and use it in GitHub Desktop.
This file contains 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 'rubygems' | |
require 'json' | |
require 'net/http' | |
module WunderGround | |
def self.query( city ) | |
api_uri = URI.parse URI.escape( "http://api.wunderground.com/api/~AKI_KEY~/geolookup/conditions/forecast/q/#{city}.json" ) | |
response = Net::HTTP.get_response api_uri | |
data = response.body | |
json = JSON.parse data | |
end | |
end | |
def display city | |
w = WunderGround.query city | |
c = w['current_observation'] | |
location = w['location']['city'] + w['location']['state'] | |
current_temp = c['temp_c'] | |
humidity = c['relative_humidity'] | |
forcast = { | |
today: { | |
day: w['forecast']['txt_forecast']['forecastday'][0]['title'], | |
str: w['forecast']['txt_forecast']['forecastday'][0]['fcttext_metric'] | |
}, | |
next: { | |
day: w['forecast']['txt_forecast']['forecastday'][1]['title'], | |
str: w['forecast']['txt_forecast']['forecastday'][1]['fcttext_metric'] | |
} | |
} | |
uv = c['UV'] | |
str = "" | |
str << "#{location}\n" | |
str << forcast[:today][:day] + "\n" | |
str << forcast[:today][:str] + "\n" | |
str << "Current Temp: #{current_temp}C\n" | |
str << "Humitidy: #{humidity}\n" | |
str << "UV: #{uv}\n" if uv.to_i > 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment