Changeset a1439aa in lab.git


Ignore:
Timestamp:
May 21, 2011 12:48:14 AM (13 years ago)
Author:
mitty <mitty@…>
Branches:
master, trunk
Children:
e3948e3
Parents:
74f778c
Message:
  • 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/pukiwikiplus/getsource.pl

    r74f778c ra1439aa  
    1111 
    1212if (@ARGV < 1) { 
    13     print "$0: url_to_pukiwikiplus_page\n"; 
     13    print "$0: [-f] url_to_pukiwikiplus_page\n"; 
    1414    exit; 
     15} 
     16 
     17my $file; 
     18if ($ARGV[0] eq '-f') { 
     19    $file = shift @ARGV; 
    1520} 
    1621 
     
    2025if ($url !~ /cmd=source/ ) { 
    2126    $url =~ s#\?(.+)#\?cmd=source&page=$1#; 
     27    if ($file) { 
     28        $file = wikifile($1) . '.txt'; 
     29    } 
    2230} 
    2331 
     
    3139my $text = $source->scrape( URI->new($url) ); 
    3240 
     41if ($file) { 
     42    print STDERR "saving: '$file'\n"; 
     43    open STDOUT, ">$file"; 
     44} 
    3345print encode('utf8', $text); 
     46 
     47 
     48sub wikifile { 
     49    my $pagename = shift @_; 
     50     
     51    $pagename =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg; 
     52    return uc unpack("H*", $pagename); 
     53} 
Note: See TracChangeset for help on using the changeset viewer.