Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use URI::URL; use POSIX; use HTML::Entities qw( encode_entities ); # Bulk node retitler my ($old,$new,$node_id) = @ARGV; die "Need the part to look for" unless $old; die "Need something to replace it with " unless defined $new; die "Need a node id" unless $node_id; $old = qr/$old/; my $agent = WWW::Mechanize->new(); $agent->env_proxy(); my ($user,$password) = ($ENV{PERLMONKS_USER},$ENV{PERLMONKS_PASS}); die "No Perlmonks password found" unless $password; die "No Perlmonks user found" unless $user; # Login and get the node-to-be-retitled $agent->get("http://www.perlmonks.org/index.pl?node_id=$node_id"); $agent->form(2); $agent->current_form->value('user', $user); $agent->current_form->value('passwd', $password ); $agent->current_form->value('expires', '+10y'); $agent->click('login'); die "No title found in node $node_id\n" unless $agent->content =~ m!<title>\s*(.+?)\s*</title>!ism; my $fulltitle = $1; my @links = @{$agent->links}; my $counter = -1; my @node_ids = map { $counter++; ($_->[1] =~ m!^(?:Re(\^\d+)?:\s*)*\Q$fulltitle\E! +i and $_->[0] =~ m!^(?:/index.pl)?\?node_id=(\d+)$!i) ? $1 : () } @links; my $history = sprintf "<p><small>%s Edit by [%s]: Changed title from ' +%s'</small></p>", strftime('%Y%m%d',gmtime()),$user, encode_entities($ +fulltitle); retitle_node($node_id,$old,$new,$history); retitle_node($_,$old,$new) for (@node_ids); sub retitle_node { my ($node_id,$old,$new,$history) = @_; $agent->get(sprintf 'http://www.perlmonks.org/index.pl?displaytype=e +ditors;node_id=%s', $node_id); $agent->form(2); my $old_title = $agent->current_form->value('update_title'); my $new_title = $old_title; $new_title =~ s!$old!$new!; if ($new_title ne $old_title) { warn "Retitling $old_title to $new_title\n"; $agent->current_form->value('update_title', $new_title); if ($history) { my $doctext = $agent->current_form->value('update_doctext') . $h +istory; $agent->current_form->value('update_doctext', $doctext); }; $agent->current_form->value('blah','update'); $agent->click('blah'); # Maybe also /msg the respective user ... }; $agent->follow_link( text => 'display'); };

In reply to Janitors' Tools - Bulk node retitler by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2014-12-27 11:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (177 votes), past polls