Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Node Bookmark Lister

by jeffa (Bishop)
on Dec 01, 2001 at 22:58 UTC ( #128896=sourcecode: print w/replies, xml ) Need Help??
Category: PerlMonks Related Scripts
Author/Contact Info jeffa
Description: UPDATE
With the new changes to the way HTML is rendered in titles, this idea is now A Bad Thing To Do ™. Please disregard this post and just think of it as a fossil. :P

A cool feature about your posts is the fact that you can put HTML comments in the title of your post. Armed with this feature, it is possible to put 'category markers' in your node titles and use a script to find them and make a nice list of your favorite nodes.

The following code will do just that, the demo is on my home node. All you need to do is mark your favorite nodes by hand with something like <!--code--> or <!--obfu-->. Well that's how i did it before i saw jcwren's Bulk Node Title Editor.

The side effect is that you have to link directly to a node's id instead of it's name when referring to it in other posts, chatbox, etc. But that's okay, you use id tags, don't you? Hey Rocko! Ask 'em if they use id tags!

Feel free to send comments and suggestions to crazyinsomniac! :D

UPDATE: - after gleaming good security info from jcwren, i changed this script to accept an interactive password similiar to how mysql asks for passwords: you can specify the password on the command line with the -p option (dangerous for mulit-user boxes), or you can just specify -p by itself and be prompted for the password. I use Term::ReadKey to keep the password 'invisible'.

use strict;

use LWP;
use Term::ReadKey;
use Getopt::Std;
use XML::Simple;
use HTTP::Request::Common;
use HTML::Template;

use constant URL => '';

$| = 1;

use vars qw(%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/<!--\s*([a-z]+)\s*-->/; # 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 $/; <DATA>};
my $template = HTML::Template->new( scalarref => \$html);
   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" }


=head1 NAME - LWP script


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 
<!--code--> or <!--neatstuff-->. The HTML template is 
included in the DATA handle for you convenience, simply 
change it to suite your needs.


  for *nix:
    ./ -u uname -p 
  for win32:
    perl -u uname -p

Invokes the script for the specified username and 
interactively prompt for password if none specified.


<table width="200" border="1">
   <tmpl_loop name="categories">
      <font face="arial,geneva,sans-serif">
      <u><tmpl_var name="category"></u>
      <font size="2">
        <tmpl_loop name="nodes">
        <li>[id://<tmpl_var name="id">|<tmpl_var name="content">]
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://128896]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-05-23 12:42 GMT
Find Nodes?
    Voting Booth?