<?xml version="1.0" encoding="windows-1252"?>
<node id="113433" title="Personal Nodelet Restorer" created="2001-09-19 18:24:56" updated="2005-08-14 04:26:42">
<type id="1748">
sourcecode</type>
<author id="34584">
$code or die</author>
<data>
<field name="doctext">
&lt;code&gt;
#!/usr/bin/perl -w
#Code adapted from http://perlmonks.com/?node=Personal%20Nodelet%20Extractor

use strict;

use LWP;
use Getopt::Std;
use HTTP::Request::Common;

$|++;
 
use vars qw(%opts);
getopts('p:u:n:h',\%opts);

my ($user,$passwd,$nodeletfile) = ($opts{u},$opts{p},$opts{n});
USAGE() and exit unless $user and $passwd and $nodeletfile and not $opts{h};

my @nodelets;
open NODELET, $nodeletfile or die "can't open nodelet file: $nodeletfile $!";
while (&lt;NODELET&gt;)
{
	next unless my ($nodelet) = /^\s*(\d+)/;
	push @nodelets, $nodelet;
}

use constant URL =&gt; 'http://www.perlmonks.org/';

my $ua = LWP::UserAgent-&gt;new;
$ua-&gt;agent('personal_nodlet_restorer/1.0 (' . $ua-&gt;agent .')');

#$ua-&gt;proxy('http', 'http://myproxy:8080');

# log in and access your User Setting page in raw format
my $request = POST(URL,
    Content =&gt; [
        op          =&gt; 'login',
        user        =&gt; $user,
        passwd      =&gt; $passwd,
        node_id     =&gt; 1072,
        displaytype =&gt; 'raw',
        addtopn	    =&gt; \@nodelets,
        modifypn    =&gt; 'on',
    ] 
);

my $response = $ua-&gt;request($request);
die $response-&gt;message unless $response-&gt;is_success;

print "All done. Please double check by logging into PerlMonks with your browser";

sub USAGE {
    print "USAGE: $0 -u user -p -password -n nodelet_filename\n";
}

=pod

=head1 NAME

restore_personal_nodelet.pl - LWP script

=head1 DESCRIPTION

Reverses the action of Jeffa's Personal Nodelet Extractor. Given a filename
that contains a list of node_ids, it will log in and add then all to your
personal nodelet.

The majority of this code was shamelessly stolen from Jeffa's Personal
Nodelet Extractor:

http://www.perlmonks.com/index.pl?node=Personal%20Nodelet%20Extractor

=head1 SYNOPSIS

for *nix:
./restore_personal_nodelet.pl C&lt;-u&gt; uname C&lt;-p&gt; passwd C&lt;-n&gt; filename 

for win32:
perl restore_personal_nodelet.pl C&lt;-u&gt; uname C&lt;-p&gt; passwd C&lt;-n&gt; filename

Invokes the script for the specified username and password. The contents on the
input file would look something like this:

	24270	Permutations and combinations
	25730	Life in the land of OOP, and I'm confused.
	17890	shift, Pop, Unshift and Push with Impunity!
	32005	Apache::MP3
	34786	Why I like functional programming

It doesn't need a default record seperator - it's collecting all numbers
so a \d+ is sufficient.

=cut

&lt;/code&gt;</field>
<field name="codedescription">
This script does the reverse of [jeffa]'s [Personal Nodelet Extractor]. It is also, mainly his code - so don't bother upvoting this node.
&lt;BR&gt;&lt;BR&gt;
I have needed to re-input all my personal nodelets twice in the last week because I have updated my sig. See [id://111627|this message] for more info. This will save me a good 20 minutes next time I have to do it! I need to do some nodelet housekeeping when I have time.
&lt;BR&gt;&lt;BR&gt;
&lt;b&gt;Update: Nov 15 2001&lt;/b&gt; Added &lt;code&gt;modifypn=&gt;'on'&lt;/code&gt; to the POST. Also modify and uncomment the line with $ua-&amp;gt;proxy if you need it. Thanks [ybiC]!</field>
<field name="codecategory">
PerlMonks.org Related Scripts</field>
<field name="codeauthor">
Simon Flack ([$code or die])</field>
</data>
</node>
