X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=Dev%2Fpukiwikiplus%2Fgetsource.pl;h=d2cf0af663b8893bbece366e57500ead1a004ae4;hb=68d6d5b003efbd06a48bd9933929cbe463738ee2;hp=905ace971e342f8394752289670c06da508b2f95;hpb=74f778c0eeed802c12174e0e6cff4851670e050d;p=lab.git diff --git a/Dev/pukiwikiplus/getsource.pl b/Dev/pukiwikiplus/getsource.pl index 905ace9..d2cf0af 100644 --- a/Dev/pukiwikiplus/getsource.pl +++ b/Dev/pukiwikiplus/getsource.pl @@ -9,25 +9,51 @@ use URI; use Data::Validate::URI qw(is_uri); use Encode; +## get wiki formatted source text from PukiWiki Plus! page +# '-f' option to save file automatically + if (@ARGV < 1) { - print "$0: url_to_pukiwikiplus_page\n"; + print "$0: [-f] url_to_pukiwikiplus_page\n"; exit; } +my $file; +if ($ARGV[0] eq '-f') { + $file = shift @ARGV; +} + my $url = $ARGV[0]; die "$0: '$url' is not URI" unless is_uri($url); if ($url !~ /cmd=source/ ) { + # set url to page of source plugin page (source.inc.php) $url =~ s#\?(.+)#\?cmd=source&page=$1#; + if ($file) { + $file = wikifile($1) . '.txt'; + } } print STDERR "getting: '$url'\n"; my $source = scraper { + # scrape page with '
' tag
     process "pre#source", "source" => "TEXT";
     result "source";
 };
 
 my $text = $source->scrape( URI->new($url) );
 
+if ($file) {
+    print STDERR "saving: '$file'\n";
+    open STDOUT, ">$file";
+}
 print encode('utf8', $text);
+
+
+sub wikifile {
+    # get wiki text filename from pagename
+    my $pagename = shift @_;
+    
+    $pagename =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg;
+    return uc unpack("H*", $pagename);
+}