Influenced by Piers Cawleys talk on the 12 Step , I confess that the following piece of code is crappy. I wrote this a few months ago, the Monastery NNTP bridge. Basically it fetches newest XML nodes and uses Net::NNTP to store it on a (local) newsserver.
#!/usr/bin/perl -w use Net::NNTP; use strict; use XML::Parser; use LWP::Simple; use Data::Dumper; #debugging purposes my $server = "192.168.0.2"; #Server my %nodetypes = ( 'bookreview' => 'monastery.reviews', 'categorized answer' => 'monastery.questions', 'categorized question' => 'monastery.questions', 'CUFP' => 'monastery.coolusesforperl', 'modulereview' => 'monastery.reviews', 'monkdiscuss' => 'monastery.discussions', 'obfuscated' => 'monastery.obfuscation', 'perlcraft' => 'monastery.craft', 'perlmeditation' => 'monastery.meditations', 'perlnews' => 'monastery.news', 'perltutorial' => 'monastery.tutorials', 'perlquestion' => 'monastery.seekersofperlwisdom', 'poem' => 'monastery.poetry', 'review' => 'monastery.reviews', 'snippet' => 'monastery.snippets', 'sourcecode' => 'monastery.code', 'tutorial' => 'monastery.tutorials', 'user' => 'monastery.users', 'note' => 'monastery.seekersofperlwisdom', ); my $parser = new XML::Parser ( Handlers => { Start => \&hdl_start, Cha +r => \&hdl_char}); my $nntp = new Net::NNTP($server,119,5); # debuglevel 5 #crappy code starts here... my $id = undef; my @Nodes = (); my $author_id = undef; my %attributes = (); my %Authors = (); my %Titles = (); my $type = undef; my $xml_stream = get("http://perlmonks.com/index.pl?node=newest+nodes+ +xml+generator"); $parser->parse($xml_stream); sub hdl_start{ my ($p, $elt, %atts) = @_; $type = $elt; if ($elt eq "NODE") { $id = $atts{node_id}; push(@Nodes,\%atts); } if ($elt eq "AUTHOR") { $author_id = $atts{node_id}; } } sub hdl_char { my ($p, $str) = @_; $str =~ s/\n//g; if ($type eq "NODE" && $str) { $Titles{$id} = $str; } if ($type eq "AUTHOR" && $str) { $Authors{$author_id} = $str; } } #open(FILE,">dump.db"); #Dump to disk #print FILE Dumper(@Nodes); #close(FILE); my $i = 0; foreach(@Nodes) { if ($i>5) { last; } $_->{author_user} = $Authors{ $_->{author_user} }; $_->{title} = $Titles{$_->{node_id} }; if (!$nntp->head("<$_->{node_id}\@localhost.localdomain>")) { my $page = get("http://www.perlmonks.org/index.pl?node_id=$_->{node_ +id}"); $page =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; #Insert HTML::Parser code + here... my @lines = split(/\n/,$page); @lines = map { $_."\n" } @lines; my @header = ( "Newsgroups: $nodetypes{$_->{nodetype}}\n", "Message-ID: <$_->{node_id}\@localhost.localdomain>\n", "Subject: $_->{title}\n", "From: $_->{author_user}\@perlmonks.org\n", exists $_->{parent_node} ? "References: <$_->{parent_node}\@l +ocalhost.localdomain>\n" : "", "\n\n", @lines); $nntp->post(\@header); print $_->{nodetype},"=>",$nodetypes{$_->{nodetype}},"\n"; $i++; } } $nntp->quit();
The replying bit is kind of tricky, also the author s email address isn't valid (unless vroom starts creating an perlmonks address for all monks).
Update: yes, it's monastery and not monestary... I blame String::Approx :)

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

In reply to Monastery NNTP Bridge by Beatnik

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.