#!/usr/local/bin/perl use Jcode; ###環境変数### #RSS化する件数 $count = 5; #picoBBSのログファイル $logfile = "./hoge/hoge.log"; #RSSのURL $rss_url = "http://diary.noasobi.net/bbs.rdf"; #BBSのタイトル $bbs_title = "朝顔日記掲示板"; #BBSのURL $bbs_url = "http://diary.noasobi.net/cgi-bin/bbs.cgi"; #RSSのタイトル $bbs_description = "朝顔日記掲示板"; #XMLスタイルシートがあれば指定(RSSファイルからのパスで) $xml_stylesheet = "rss2html.xsl"; #グリニッジ標準時間誤差 $GMT = "+09:00"; ############## #スクリプトバージョン $version = "1.2"; #スクリプト名 $PROGRAM_NAME = "log2rss.pl"; ###取り出すデータ保存変数### my $title; my $comment; my $id; my $name; my $date; my $rss; #################### $xml_code = "UTF-8"; $out_code = "utf8"; $out_file = ""; ###引数処理#### my $opt; while ($opt = shift @ARGV){ if($opt eq "-c" ){ $opt = shift @ARGV; if($opt !~ /[0-9]*/){ &error("-c 表示する件数"); } $count = $opt; } elsif($opt eq "-l"){ $opt = shift @ARGV; if(!-e $opt){ &error("-l ログファイル名\n$optが見つかりません。"); } $logfile = $opt; } elsif($opt eq "-o"){ $opt = shift @ARGV; if($opt !~ /\S+/){ &error("-o 出力RSSファイル名\n出力するファイル名を指定してください。"); } $out_file = $opt; } elsif($opt eq "-s") { $xml_code = "Shift-JIS"; $out_code = "sjis"; } elsif($opt eq "-u") { $xml_code = "UTF-8"; $out_code = "utf8"; } elsif($opt eq "-e") { $xml_code = "EUC"; $out_code = "euc"; } elsif($opt eq "-h") { &print_help; } elsif($opt eq "-v") { print "$PROGRAM_NAME:ver.$version\n"; exit; } } open(LOG,"$logfile") || &error("ファイルが開けません::$logfile"); @all = ; close(LOG); $rss .= << "__RSS"; __RSS if($xml_stylesheet ne ""){ $rss .= "\n"; } $rss .= << "__RSS"; $bbs_title $bbs_url $bbs_description __RSS for ($i=1;$i <= $count;$i++) { $rss .= " \n"; } $rss .= << "__RSS"; __RSS $rss .= "\n"; for ($i=1;$i <= $count;$i++) { $line = $all[$#all-$i+1]; @data = split("\c@",$line); $name = $data[4]; $date = $data[2]; $id = $data[0]; $title = $data[6]; @topcomment = split("\cM",$data[7]); $comment = $topcomment[0]; $comment =~ s//\>\;/g; $date = &convert_date($date); $rss .= " \n"; $rss .= " [$id]$title ($name)\n"; $rss .= " $bbs_url#PrintNo$i\n"; $rss .= " $comment\n"; $rss .= " $date\n"; $rss .= " \n"; $rss .= "\n"; } $rss .= "\n"; Jcode::convert(\$rss,"$out_code"); if($out_file ne ""){ open(OUT,">$out_file") || &error("$out_fileが開けません"); print OUT "$rss"; close(OUT); print "$out_fileに書き出しました。\n"; } else{ print "$rss"; } exit; sub error{ print "ERROR:$_[0]\n"; print "異常終了します。"; exit; } sub print_help{ print "$PROGRAM_NAME:ver.$version\n"; print "使い方:$PROGRAM_NAME [-v | -h | -l ログファイル名 | -o 出力ファイル名 | -e | -s | -u ]\n"; print "-h : ヘルプ(これ)を表示します。\n"; print "-v : プログラムのバージョンを表示します。\n"; print "-l ログファイル名 : picoBBSのログファイルを指定します。\n"; print "-o 出力ファイル名 : 出力RSSファイル名を指定します。\n"; print "-e : EUCで出力します。\n"; print "-s : Shift_JISで出力します。\n"; print "-u : UTF-8で出力します。\n"; exit; } sub convert_date{ $_[0] =~ s/\//-/g; $_[0] =~ s/([0-9]+-[0-9]+-[0-9]+)\s([0-9]+:[0-9]+)/$1T$2$GMT/; return $_[0]; }