Skip to content

Instantly share code, notes, and snippets.

@addisonhuddy
Created February 26, 2013 23:26
Show Gist options
  • Save addisonhuddy/5043332 to your computer and use it in GitHub Desktop.
Save addisonhuddy/5043332 to your computer and use it in GitHub Desktop.
Weather App using Weather Underground API
!/usr/bin/env ruby
#writing an app to let me get the local weather whenever I type 'weather' into the terminal
# Weather Undergroud API Key
# 47b910e89d1eff6a
# http://api.wunderground.com/api/47b910e89d1eff6a/geolookup/conditions/q/CA/Palo_Alto.json
require 'json'
require 'open-uri'
open('http://api.wunderground.com/api/47b910e89d1eff6a/geolookup/conditions/q/CA/Palo_Alto.json') do |a|
json_string = a.read
parsed_json = JSON.parse(json_string)
location = parsed_json['location']['city']
temp = parsed_json['current_observation']['temp_f'].round(0)
wind = parsed_json['current_observation']['wind_mph']
puts "Weather for #{location}: #{temp}F, #{wind}mph"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment