LoginSignup
5
6

More than 5 years have passed since last update.

Ruby | ライブドア天気情報「Weather Hacks」の結果を取得する

Posted at

Ruby | ライブドア天気情報「Weather Hacks」の結果を取得する

概要

ライブドア天気情報「Weather Hacks」の結果を取得します

仕様

東京の天気情報を取得します
http://weather.livedoor.com/forecast/webservice/json/v1?city=130010

サンプルコード

require 'net/http'
require 'uri'
require 'json'

uri = URI.parse('http://weather.livedoor.com/forecast/webservice/json/v1?city=130010')
json = Net::HTTP.get(uri)
result = JSON.parse(json)
print result['title'], "\n"
print result['link'], "\n"
print "予報の発表日時:#{result['publicTime']}", "\n"
result['forecasts'].each do |forecast|
  print "--------------------"
  print "予報日:#{forecast['dateLabel']}", "\n"
  print "天気:#{forecast['telop']}", "\n"
  print "最低気温:#{forecast['temperature']['min']}", "\n"
  print "最高気温:#{forecast['temperature']['max']}", "\n"
end

出力

東京都 東京 の天気
http://weather.livedoor.com/area/forecast/130010
予報の発表日時:2014-08-30T17:00:00+0900
--------------------予報日:今日
天気:曇り
最低気温:
最高気温:
--------------------予報日:明日
天気:曇のち雨
最低気温:{"celsius"=>"21", "fahrenheit"=>"69.8"}
最高気温:{"celsius"=>"26", "fahrenheit"=>"78.8"}
--------------------予報日:明後日
天気:曇時々雨
最低気温:
最高気温:

参照

http://weather.livedoor.com/weather_hacks/
http://weather.livedoor.com/weather_hacks/webservice

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6