#!/usr/bin/env ruby # [2003/12/30] by rubikitch # Yahoo!天気予報をPalmに取り込む # 要plucker-build, w3m # 45行目付近も必要に応じて書き換えるといいかも。(出力ファイルがそのまま書かれているので) # 地域によって変える。 URL="http://weather.yahoo.co.jp/weather/jp/13/13210/44116.html" def main(src) today, tomorrow = src.scan(%r! - (\d+)月(\d+)日\(.+\)!) temperature_ary = src.scan(%r!(\d+)!).flatten humidity_ary = src.scan(%r!(\d+)!).flatten rain_ary = src.scan(%r!(\d+)!).flatten weather_ary = src.scan(/\A(.+\n)/m).to_s.scan(%r!^(.+)$!).flatten.delete_if{|x| x=~/(.+?)
\n(\d+)
!).collect{|x,y| x+y} time_ary = src.scan(%r!^(.+時)$!).flatten date_ary = make_date_ary(time_ary, today[1], tomorrow[1]) puts "" puts "

天気

" output date_ary, time_ary, weather_ary, temperature_ary, humidity_ary, rain_ary, wind_ary puts "" end def make_date_ary(ary, today, tomorrow) x = 0 ary.collect {|y| hour = y[0..-3].to_i ((hour > x) ? today : tomorrow) + "日" } end def output(date_ary, time_ary, weather_ary, temperature_ary, humidity_ary, rain_ary, wind_ary) puts "" end def pluck system < /l/log/weather.html plucker-build -H /l/log/weather.html -f weather rm /l/log/weather.html END end def text system < /l/log/weather.txt END end if __FILE__==$0 #main(File.read "/tmp/w.html") require 'getopts' getopts 'pt' if $OPT_p pluck elsif $OPT_t text else main ARGF.read end end