お天気ワンライ……ナぁ……?
$ ruby -r json -r yaml -e 'YAML::dump((JSON.parse!(`curl http://weather.livedoor.com/forecast/webservice/json/v1?city=130010`))["forecasts"], $stdout)'
……Mac Book Air の13インチの画面には収まったからワンライナーとは言えますよね!!
本当はcurbというcurlを便利に使うgemを使いたかったのですが……
使い方がよくわかってないのでパスしました
具体的な動き
curl
例の如くお天気系APIを叩いて結果を頂いています。
APIはコチラを利用させて貰いました。
http://weather.livedoor.com/weather_hacks/webservice
結果はjsonで返って来ます
商用利用でなければ、特に制約はないみたいです。
実行結果(東京= city:130010)
$ ##上のスクリプト##
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8360 0 8360 0 0 85747 0 --:--:-- --:--:-- --:--:-- 103k
---
- dateLabel: 今日
telop: 曇のち晴
date: '2013-11-04'
temperature:
min:
max:
image:
width: 50
url: http://weather.livedoor.com/img/icon/12.gif
title: 曇のち晴
height: 31
- dateLabel: 明日
telop: 晴れ
date: '2013-11-05'
temperature:
min:
celsius: '13'
fahrenheit: '55.4'
max:
celsius: '18'
fahrenheit: '64.4'
image:
width: 50
url: http://weather.livedoor.com/img/icon/1.gif
title: 晴れ
height: 31
- dateLabel: 明後日
telop: 晴時々曇
date: '2013-11-06'
temperature:
min:
max:
image:
width: 50
url: http://weather.livedoor.com/img/icon/2.gif
title: 晴時々曇
height: 31
編集
11/4 curlをパイプで繋げてたけど よく考えたらバッククォートで十分だった事に気付く