Skip to content

Instantly share code, notes, and snippets.

@dylanj
Created July 9, 2012 18:03
Show Gist options
  • Save dylanj/3077921 to your computer and use it in GitHub Desktop.
Save dylanj/3077921 to your computer and use it in GitHub Desktop.
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