Skip to content

Instantly share code, notes, and snippets.

@garin
Last active August 29, 2015 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garin/1f41735320a5659e114c to your computer and use it in GitHub Desktop.
Save garin/1f41735320a5659e114c to your computer and use it in GitHub Desktop.
#!/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