################################################################################ # 名 称 :HNStenkiJP 用 MTWeatherJP.pm # # 機 能 :Japan Weather Forecast xml を元に天気情報を表示する MT plugin # # 備 考 :全ての情報は気象庁からのみ取得してます # # ver 0.x とのタグ互換もあり。ただし花粉情報は無効となった # # # # 作成年月日 :v0.01 2003.12.13 # # 修正年月日 :v0.02 2004.03.23 imageディレクトリの指定を可能にした # # 修正年月日 :v0.03 2004.03.30 encodeの指定を可能にした # # 修正年月日 :v0.04 2004.10.26 天気画像が存在しない場合の処理を対応 # # 修正年月日 :v0.05 2005.01.22 花粉情報を取得するよう処理追加 # # 修正年月日 :v0.06 2005.02.01 花粉情報「長崎地方」を修正 # # 修正年月日 :v0.07 2005.06.01 エラー処理を強化 # # 修正年月日 :v1.00 2005.07.24 # # 修正年月日 :v1.01 2005.07.24 tagの衝突をbug-fix # # 修正年月日 :v1.02 2005.07.31 Charset をMT::ConfigMgr から取得するよう変更 # # 修正年月日 :v1.03 2005.08.05 気象庁の8月リニューアルに対応 # # 修正年月日 :v1.04 2005.08.25 各種バグ対応 # # 修正年月日 :v1.05 2005.09.02 文字化け対応。utfflagオプション # # 修正年月日 :v1.06 2005.09.03 文字化け対応。更に調整 # # 修正年月日 :v1.07 2005.09.04 文字化け対応。泣く泣くDrk::Dateの使用を停止 # # 修正年月日 :v1.07a 2005.09.04 _date の typo 修正 # # 修正年月日 :v1.07b 2005.09.04 xml parse 部分のみ使用するように変更 # # 作 成 者 :drk # # 編 集 者 :LAC http://x68k.net # # Copy Right :http://www.drk7.jp # ################################################################################ package MTWeatherJP; use strict; use vars qw( $VERSION ); $VERSION = '1.07b'; use Jcode; use XML::Simple; use FileHandle; ###--------------------------------------------------------------------------### # 天気情報取得Private関数 ###--------------------------------------------------------------------------### sub _parse_weather_xml { my($ctx, $xml, $imgpath, $args) = @_; ## XMLパース -> 配列格納 my @area = XMLin($xml, ForceArray => ["area"])->{pref}->{area}; my $code = $args->{ie}; ## ctx->stash へ結果格納 my $i=0; my $weathers = []; my $utfmodule = 0; eval{ require utf8; $utfmodule = 1; }; map{ my $data=$_; foreach(keys %$data) { my $area = $_; my $info = $data->{$area}->{info}; my $area_tmp = $area; ## 取得したいエリアのみを解析対象とする eval{ utf8::decode($area_tmp); utf8::encode($area_tmp) if($utfmodule||$args->{utfflag}); }; my $area_euc = Jcode->new($area_tmp, 'utf8')->euc; next if($args->{area} ne $area_euc); map { my $e = $_; my $date =$e->{date}; # my $weather =$e->{weather}||''; my $weather =$e->{weather_detail}||''; my $weatherdetail =$e->{weather_detail}||''; my $img =$e->{img}||''; my $wave =$e->{wave}||''; my $tempmax =$e->{temperature}->{range}->[0]->{content}; my $tempmin =$e->{temperature}->{range}->[1]->{content}; my $rain00 =$e->{rainfallchance}->{period}->[0]->{content}; my $rain06 =$e->{rainfallchance}->{period}->[1]->{content}; my $rain12 =$e->{rainfallchance}->{period}->[2]->{content}; my $rain18 =$e->{rainfallchance}->{period}->[3]->{content}; $wave=""; eval{ utf8::decode($weather); utf8::decode($weatherdetail); utf8::decode($wave); if($utfmodule||$args->{utfflag}) { utf8::encode($weather); utf8::encode($weatherdetail); utf8::encode($wave); } }; $img =~ s!http://www.drk7.jp/MT/images/MTWeather/!!; $img = $imgpath.$img; ($date)= $date=~m!\d\d/\d\d/(\d\d)!;; if($args->{ie} ne 'utf8') { $weather = Jcode->new($weather,'utf8')->$code; $weatherdetail = Jcode->new($weatherdetail,'utf8')->$code; $wave = Jcode->new($wave,'utf8')->$code; } push @$weathers, { Pref => Jcode->new($args->{pref},'euc')->$code, Area => $area_tmp, WeatherDate => $date, Weather => $weather, WeatherDetail => $weatherdetail, WeatherImg => $img, Wave => $wave, TempMax => $tempmax, TempMin => $tempmin, Rain00 => $rain00, Rain06 => $rain06, Rain12 => $rain12, Rain18 => $rain18, }; } @$info; } } @area; return $weathers; } 1;