use strict; use LWP; use Term::ReadKey; use Getopt::Std; use XML::Simple; use HTTP::Request::Common; use HTML::Template; use constant URL => 'http://www.perlmonks.org/'; $| = 1; use vars qw(%opts); getopts('p:u:h',\%opts); my ($user,$passwd,$help) = parse_args(\%opts); USAGE() and exit unless $user and $passwd and not $help; my $ua = LWP::UserAgent->new; $ua->agent("all_node_grabber($user)/1.0 (" . $ua->agent .')'); # log in and access your nodes info xml page my $request = POST(URL, Content => [ op => 'login', user => $user, passwd => $passwd, node => 'User nodes info xml generator', ]); my $response = $ua->request($request); # prepare xml my $xml = $response->content(); # i have two nodes that have the registerd and copyright # symbols in them - the next two lines were necesary - YMMV $xml =~ s/©//g; $xml =~ s/®//g; $xml = XMLin($xml,forcearray=>1) or die "xml error!"; # munge data my %bookmarks; my $marker = qr//; # YMMV here too while(my($node_id,$hash) = each %{$xml->{'NODE'}}) { my $content = $hash->{'content'}; my ($category) = $content =~ /$marker/; next unless $category; # the next three lines are specific to me - YMMV $category = ucfirst $category . 's'; $content =~ s/$marker(?:\($user\))*\s*\d*//; $content =~ s/(.{24}).{3,}/$1.../; push @{$bookmarks{$category}}, {id=>$node_id, content=>$content}; } # prepare template my $html = do {local $/; }; my $template = HTML::Template->new( scalarref => \$html); $template->param( categories => [ map {{ category => $_, nodes => $bookmarks{$_} }} sort keys %bookmarks # feel free to customize this sort ]); # print template print $template->output(); sub parse_args { my %opt = %{+shift}; if (exists $opt{'p'} and not defined $opt{'p'} and defined $opt{'u'}) { print "Enter password: "; ReadMode 'noecho'; chomp($opt{'p'} = ReadLine 0); ReadMode 'normal'; } return @opt{qw(u p h)}; } sub USAGE { print "USAGE: $0 -u user -p -password\n" } =pod =head1 NAME node_bookmark_lister.pl - LWP script =head1 DESCRIPTION This is a simple script that uses LWP, XML::Simple, and HTML::Template to produce an HTML table of nodes whose titles you have marked with an HMTL comment, such as or . The HTML template is included in the DATA handle for you convenience, simply change it to suite your needs. =head1 SYNOPSIS for *nix: ./node_bookmark_lister.pl -u uname -p for win32: perl node_bookmark_lister.pl -u uname -p Invokes the script for the specified username and interactively prompt for password if none specified. =cut __DATA__
  • [id://|]