# -*- encoding: utf-8 -*- # author : nocd5 # date : 2009/09/21 require 'rss' require 'kconv' #################################### LOCALE = ARGV[0] BLACKBOX = 'C:\bbLean\blackbox.exe' OUTPUTFILE = 'C:\bbLean\weather.rc' ICONFOLDER = 'C:\bbLean\script\ico' #################################### HOST = 'http://rss.weather.yahoo.co.jp/rss/days/' #################################### #################################### if LOCALE.nil? puts "4410 : 東京".tosjis exit end #################################### hashico = {'晴れ' => "sun.ico", '晴時々曇' => "sun_clouds_st.ico", '晴時々雨' => "sun_rain_st.ico", '晴時々雪' => "sun_snow_st.ico", '晴後曇' => "sun_clouds_af.ico", '晴後雨' => "sun_rain_af.ico", '晴後雪' => "sun_snow_af.ico", '曇り' => "clouds.ico", '曇時々晴' => "clouds_sun_st.ico", '曇時々雨' => "clouds_rain_st.ico", '曇時々雪' => "clouds_snow_st.ico", '曇後晴' => "clouds_sun_af.ico", '曇後雨' => "clouds_rain_af.ico", '曇後雪' => "clouds_snow_af.ico", '雨' => "rain.ico", '雨時々晴' => "rain_sun_st.ico", '雨時々曇' => "rain_clouds_st.ico", '雨時々雪' => "rain_snow_st.ico", '雨後晴' => "rain_sun_af.ico", '雨後曇' => "rain_clouds_af.ico", '雨後雪' => "rain_snow_af.ico", '雪' => "snow.ico", '雪時々晴' => "snow_sun_st.ico", '雪時々曇' => "snow_clouds_st.ico", '雪時々雨' => "snow_rain_st.ico", '雪後晴' => "snow_sun_af.ico", '雪後曇' => "snow_clouds_af.ico", '雪後雨' => "snow_rain_af.ico" } #################################### xml = open("#{HOST}#{LOCALE}.xml").read.gsub!(/.*?<\/pubDate>/, "") exit if xml.nil? rss = RSS::Parser.parse(xml) rss.output_encoding = 'UTF-8' list = [] alert = [] is_alert = false nMaxLenD = 0 nMaxLenH = 0 nMaxLenL = 0 rss.items.each do |item| tmp = item.title if tmp =~/【\s*(.*?)\s*】注意報があります.*/ if !is_alert alert.push "[separator]" alert.push "[exec] (注意報があります) {#{item.link}} " end is_alert = true alert.push "[nop] (#{$1})" end tmp.gsub! /\s*(?:【|】)\s*/, '' tmp.gsub! /\ -\ Yahoo!天気情報$/, '' tmp.gsub! /\[PR\].*/, '' if tmp =~ /(\d+)日.*?((.*?)).*)\s*(.*?) - .*?((?:-?\d+)|(?:---))℃\/((?:-?\d+)|(?:---))℃/ # get maximum length nMaxLenD = [nMaxLenD, $1.length].max nMaxLenH = [nMaxLenH, $4.length].max nMaxLenL = [nMaxLenL, $5.length].max # date, week, hight, low, weather list.push [$1, $2, $4, $5, $3, item.link] end end output = [] output.push "[begin] (Yahoo!天気情報)" output.push rss.channel.title.gsub!(/Yahoo!天気情報 - (.*)/,"[exec] (\\1){#{rss.channel.link}}") output.push "[separator]" list.each do |data| date = ' '*(nMaxLenD - data[0].length) + data[0] week = data[1] tmax = ' '*(nMaxLenH - data[2].length) + data[2] tmin = ' '*(nMaxLenL - data[3].length) + data[3] weather = data[4] output.push "[nop] (#{date} (#{week}) #{tmax}℃ / #{tmin}℃ #{weather}) <\"#{ICONFOLDER}\\#{hashico[weather]}\">" end # add alert output.concat alert output.push "[end]" # file out ofile = open(OUTPUTFILE, "w") output.each do |item| ofile.puts item.tosjis end ofile.close # show menu system("#{BLACKBOX} -exec @BBCore.ShowMenu #{OUTPUTFILE}")