From a1439aaec93e5fbdc5973c87763069cd24c4e4a5 Mon Sep 17 00:00:00 2001 From: mitty Date: Fri, 20 May 2011 15:48:14 +0000 Subject: [PATCH] * accept -f option to save wiki text to file git-svn-id: https://lab.mitty.jp/svn/lab/trunk@121 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- Dev/pukiwikiplus/getsource.pl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Dev/pukiwikiplus/getsource.pl b/Dev/pukiwikiplus/getsource.pl index 905ace9..10fcc37 100644 --- a/Dev/pukiwikiplus/getsource.pl +++ b/Dev/pukiwikiplus/getsource.pl @@ -10,15 +10,23 @@ use Data::Validate::URI qw(is_uri); use Encode; 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/ ) { $url =~ s#\?(.+)#\?cmd=source&page=$1#; + if ($file) { + $file = wikifile($1) . '.txt'; + } } print STDERR "getting: '$url'\n"; @@ -30,4 +38,16 @@ my $source = scraper { my $text = $source->scrape( URI->new($url) ); +if ($file) { + print STDERR "saving: '$file'\n"; + open STDOUT, ">$file"; +} print encode('utf8', $text); + + +sub wikifile { + my $pagename = shift @_; + + $pagename =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg; + return uc unpack("H*", $pagename); +} -- 1.7.9.5