Changeset 121 in lab


Ignore:
Timestamp:
May 21, 2011 12:48:14 AM (11 years ago)
Author:
mitty
Message:
  • accept -f option to save wiki text to file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Dev/pukiwikiplus/getsource.pl

    r120 r121  
    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.