Last active
August 29, 2015 14:26
-
-
Save garin/1f41735320a5659e114c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# original to : https://gist.github.com/yuhkikame/d2adf493c0308f247682 | |
# | |
# // show all main weather data | |
# $ ruby weather.rb | |
# temp 32.39 | |
# pressure 1006 | |
# ... | |
# | |
# // show temp data only | |
# $ ruby weather.rb | grep -E "^temp\s+" | cut -d " " -f 2 | |
# 32.39 | |
# | |
require 'open-uri' | |
require 'json' | |
country = ARGV[0] || "jp" | |
location = ARGV[1] || "tokyo" | |
uri = "http://api.openweathermap.org/data/2.5/weather?q=#{location},#{country}&units=metric" | |
weather = JSON.parse(open(uri).read)["main"] | |
%w(temp pressure humidity temp_min temp_max).each do |t| | |
puts "#{t} #{weather[t]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment