[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(DTPtechNote:1317) Re: [XML] Weather Hacks
#! /usr/local/bin/ruby -Ku
=begin
livedoor_weather.rb
(c)2006 www.seuzo.jp
Usage;
livedoor_weather.rb <encode> <city>
<encode> 出力文字コード
-j jis(iso-2022-jp)
-e EUC_JP
-s Shift JIS
-w UTF-8
<city> cityコードはhttp://weather.livedoor.com/forecast/rss/forecastmap.xmlを参照
63 東京都
60 さいたま市
History;
2006.3.5 ver. 0.1 とりあえず
=end
require 'open-uri'
require 'rexml/document'
require 'nkf'
my_encode = ARGV[0]
my_city = ARGV[1]
my_uri = URI.parse('http://weather.livedoor.com/forecast/webservice/rest/v1?city='+ my_city + '&day=tomorrow')
my_html = my_uri.read
my_doc = REXML::Document.new(my_html)
my_title = my_doc.root.get_text("title").to_s
my_telop = my_doc.root.get_text("telop").to_s
my_description = my_doc.root.get_text("description").to_s
my_link = my_doc.root.get_text("link").to_s
print NKF.nkf("-W #{my_encode}", "#{my_title}\n#{my_telop}\n#{my_description}\n#{my_link}\n")