Last active
December 19, 2015 03:39
-
-
Save siwasu17/5891984 to your computer and use it in GitHub Desktop.
Open Weather Map http://openweathermap.org/
を呼び出す練習
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 | |
# -*- encoding: utf-8 -*- | |
require 'open-uri' | |
require 'json' | |
# 池袋 | |
#緯度:35.728926 経度:139.71038 | |
lat=35.7280926 | |
lon=139.71038 | |
url = "http://api.openweathermap.org/data/2.5/forecast?lat=#{lat}&lon=#{lon}&mode=json" | |
p url | |
json_object = JSON.parse(open(url).read) | |
#p jj(json_object) | |
#h_after = 1 | |
#p json_object["list"][h_after/3]["weather"][0]["description"] | |
now = Time.now.to_i | |
p "Now: #{now}" | |
json_object["list"].each do |v| | |
forcast_time = v["dt"] | |
if (forcast_time > now) && (forcast_time <= (now + 57600)) then | |
p v["weather"][0]["main"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment