Created
February 26, 2013 23:26
-
-
Save addisonhuddy/5043332 to your computer and use it in GitHub Desktop.
Weather App using Weather Underground API
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
!/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