The Everything 2 Auto-Noder is a JeffMagnus product that facilitates auto-noding on the Everything system. An old version of this script may have been partially responsbile for crashing E2, so be careful.

Contact me with any questions, comments, suggestions, and nude pictures of your motherboard.


#!/usr/bin/perl -w
#
# The New JeffMagnus Auto-Noder
#
#
use strict;

use lib ("/home/jc82/lib/perl5/site_perl/5.005/");

# Create a user agent object
use LWP::UserAgent;
use CGI;

my %numeric_types = ('person', 249, 'place', 252, 'idea', 251, 'thing', 250);

sub main
{
  my $ua = new LWP::UserAgent;
  $ua->agent('Auto-JeffMagnus/2.0 (' . $ua->agent . ')');

  $| = 1;

  my ( $stage, $key, %nodes );

  $stage = 1;

  while(<>)
  {
    chomp;
    if($stage == 1)
    {
      $stage = 2;
      $key = $_;
    }
    elsif($stage == 2)
    {
      $nodes{$key}->{'type'} = $_;
      $stage = 3;
    }
    elsif($stage == 3)
    {
      if($_ eq "----")
      {
        $stage = 1;
      }
      else
      {
        $nodes{$key}->{'text'}.="$_\n";
      }
    }
  }

  foreach $key (keys %nodes)
  {
    print "Creating [$key]...\n";
    
    my ( $node_id, $parent_node_id, $isnew ) = create_shell($key, $ua);
    unless(defined $node_id)
    {
      warn "Error creating [$key]!";
      open(SLOP, ">>node.error") or next;
      print SLOP "$key\n";
      print SLOP "$nodes{$key}->{'type'}\n";
      print SLOP "$nodes{$key}->{'text'}\n";
      print SLOP "----\n";
      close SLOP;
      next;
    }

    unless($isnew)
    {
      print 'Already has writeup. Replacing ';
    }
    print "Node-ID: [$node_id] Parent-Node-ID: [$parent_node_id]\n";

    if(populate_shell($node_id, $parent_node_id, $isnew, $nodes{$key}->{'type'},
      $nodes{$key}->{'text'}, $ua))
    {
      print "Noding should have worked...\n";
    }
    else
    {
      print "Failed to create...\n";
    }
  }

  return 0;
}

sub create_shell
{
  my ( $title, $ua ) = @_;
  my ( $node_id, $parent_node_id, $isnew );
  
  # Create a request
  my $req = new HTTP::Request
    POST => 'http://www.everything2.com/?node_id=365128&lastnode_id=124';

  $req->content_type('application/x-www-form-urlencoded');
  $req->header('Cookie' =>
    'userpass=Your User Name and Encrypted Password; path=/; expires= 10y');

  my $oneCGI = new CGI({'node'=>$title, 'op'=>'new',
    'type'=>'e2node', 'createit'=>'Create It!'});
    
  $req->content($oneCGI->query_string());

  # Pass request to the user agent and get a response back
  my $res = $ua->request($req);

  # Check the outcome of the response
  if ($res->is_success)
  {
    $_ = $res->content;

    if( $_ =~ /<INPUT TYPE=HIDDEN NAME=\"node\" VALUE=\"(\d*)\">
        <INPUT TYPE=checkbox NAME=writeup_notnew VALUE=1>
        \(Don't display in \"New Writeups\"\)
        <p><b>Enter your writeup<\/b><br>
        <TEXTAREA NAME=\"writeup_doctext\" ROWS=20 COLS=60 wrap=virtual>
        <\/TEXTAREA><br>
        <INPUT TYPE=hidden NAME=\"writeup_parent_e2node\" VALUE=\"(\d*)\">/ )
    {
      $node_id = $1;
      $parent_node_id = $2;
      $isnew = 1;
    }
    if( $_ =~ /<INPUT TYPE=HIDDEN NAME=\"node_id\" VALUE=\"(\d*)\"><b>Set/ )
    {
      $node_id = $1;
      $isnew = 0;
    }
    if( $_ =~ /<INPUT TYPE=hidden NAME=\"writeup_parent_e2node\" VALUE=\"(\d*)\">
        <INPUT TYPE=\"submit\" NAME=\"sexisgood\" VALUE=\"sumbit\">/ )
    {
      $parent_node_id = $1;
    }
  }

  return ( $node_id, $parent_node_id, $isnew );
} # end create shell

sub populate_shell
{
  my ( $node_id, $parent_node_id, $isnew, $type, $text, $ua ) = @_;
  
  # Create a request
  my $req = new HTTP::Request
    POST => 'http://www.everything2.com/?node_id=365128&lastnode_id=124';

  $req->content_type('application/x-www-form-urlencoded');
  $req->header('Cookie' =>
    'userpass=Your User Name and Encrypted Password; path=/; expires= 10y');

  my $oneCGI;
  
  if($isnew)
  {
    $oneCGI = new CGI({'node'=>'new writeup', 'op'=>'new', 'type'=>'writeup',
      'node'=>$node_id, 'writeup_doctext'=>$text,
      'writeup_parent_e2node'=>$parent_node_id, 'writeuptype'=>$type});
  }
  else
  {
    $oneCGI = new CGI({'node_id'=>$node_id,
      'writeup_wrtype_writeuptype'=>$numeric_types{$type},
      'writeup_doctext'=>$text, 'writeup_parent_e2node'=>$parent_node_id});
  }
    
  $req->content($oneCGI->query_string());

  # Pass request to the user agent and get a response back
  my $res = $ua->request($req);

  # Check the outcome of the response
  if ($res->is_success)
  {
    return 1;
  }

  return 0;
}

&main;