🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
2 messages
2 total messages Started by Gerry Ford Thu, 17 Apr 2008 23:56
perl clients and a newsgroup list
#219487
Author: Gerry Ford
Date: Thu, 17 Apr 2008 23:56
100 lines
4655 bytes
I've been looking at Mats Peterson's client for the last week.  He has a 
perl script and a resource file for things like your server name.

It occurs to me that a person would want to have another resource file of 
some type that will hold the list of newsgroups.  With my newsfeed, there's 
100,000 of them, and I use a 56K dial-up, so it takes five or ten minutes. 
When I fire up OE or binary vortex for the first time, it says "hold on, I'm 
downloading the list of newsgroups.  This could take a while, but you 
prettymuch only have to do it once."  Consequently it has to be serialized 
somehow.

When I've had my minimal clients before, I would hard-code the group I was 
looking at, like so:
#!/usr/bin/perl -w

use strict;
use Net::NNTP ();

use constant NUMBER_OF_ARTICLES    => 100;
use constant GROUP_NAME        => 'comp.lang.c';
use constant SERVER_NAME    => 'news.newsgroups.com';
use constant NNTP_DEBUG        => 0;

my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = 'wade196884';
my $PASS = '';

$nntp->authinfo($USER,$PASS) or die $!;


my($article_count, $first_article, $last_article) = $nntp->group(GROUP_NAME) 
or die;


# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};

my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >= 
$first_article) {

    # How many articles do we need?  Stop retrieving if we have enough
    my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last 
RETRIEVE;


    # Fetch overview information for the articles
    $start_article = $last_article - ($articles_required-1);
    $start_article = $start_article > $first_article ? $start_article : 
$first_article;

    my $xover_query = $start_article == $last_article ?
    $start_article :
    [$start_article, $last_article];
    my $xover_ref = $nntp->xover($xover_query) or die;

    # Store headers for the articles we've retrieved
    foreach (sort {$b <=> $a} keys %$xover_ref) {
        push @xover, $xover_ref->{$_};
    }
} continue {
    # Move the pointer forward to fetch previous articles
    $last_article = $start_article - 1;
}

# Disconnect from the NNTP server
$nntp->quit;

print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset], 
@xover)),"\n";

#  perl mats1.pl 2>text50.txt >text51.txt
__END__

In Mats' script I think he gets the group list so:
sub get_all_groups {
    my $groups = $nntp->list() or do {prompt $nntp; return};
    $_ = prompt('File name: '); length or return;
    open(FILE, ">$_") or die "open: $!\n";
    print FILE "$_!\n" foreach (sort keys %$groups);
    close(FILE);
}

The nntp object is already instantiated, and  it looks like the list() 
method is the workhorse here.  How would I get all the groups using my 
bare-bones script and write them to a FILE?  One answer might be that it's 
right in front of my nose, but I have trouble following execution in perl.

-- 
"A belief in a supernatural source of evil is not necessary; men alone
are quite capable of every wickedness."

~~  Joseph Conrad (1857-1924), novelist 

Re: perl clients and a newsgroup list
#219629
Author: Gerry Ford
Date: Sun, 20 Apr 2008 05:58
119 lines
4835 bytes
"Gerry Ford" <gerry@nowhere.ford> wrote in message 
news:1208476119_34@news.newsgroups.com...
>
> I've been looking at Mats Peterson's client for the last week.  He has a 
> perl script and a resource file for things like your server name.
>
> It occurs to me that a person would want to have another resource file of 
> some type that will hold the list of newsgroups.  With my newsfeed, 
> there's 100,000 of them, and I use a 56K dial-up, so it takes five or ten 
> minutes. When I fire up OE or binary vortex for the first time, it says 
> "hold on, I'm downloading the list of newsgroups.  This could take a 
> while, but you prettymuch only have to do it once."  Consequently it has 
> to be serialized somehow.


This script puts a file called newssrc2.txt in the same folder whence the 
scirpt is executed.  It contains an alphabetically-sorted list of everything 
your server wants to consider an ng. http://zaxfuuq.net/perl153.jpg .  To 
execute fully on a 56K modem, I needed 15 minutes.

#!/usr/bin/perl -w

use strict;
use Net::NNTP ();

use constant NUMBER_OF_ARTICLES    => 3;
use constant GROUP_NAME        => 'comp.lang.c';
use constant SERVER_NAME    => 'news.newsgroups.com';
use constant NNTP_DEBUG        => 1;

my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = 'wade196884';
my $PASS = '';

my %settings = (
    SERVER_NAME => '127.0.0.1',
    SERVER_PORT => 563,
    NEWSRC      => 'newsrc2.txt',
    DEBUG       => 1,
);

$nntp->authinfo($USER,$PASS) or die $!;


my($article_count, $first_article, $last_article) =

$nntp->group(GROUP_NAME) or die;


# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};

my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >=

$first_article) {

    # How many articles do we need?  Stop retrieving if we have enough
    my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last

RETRIEVE;


    # Fetch overview information for the articles
    $start_article = $last_article - ($articles_required-1);
    $start_article = $start_article > $first_article ? $start_article :

$first_article;

    my $xover_query = $start_article == $last_article ?
    $start_article :
    [$start_article, $last_article];
    my $xover_ref = $nntp->xover($xover_query) or die;

    # Store headers for the articles we've retrieved
    foreach (sort {$b <=> $a} keys %$xover_ref) {
        push @xover, $xover_ref->{$_};
    }
} continue {
    # Move the pointer forward to fetch previous articles
    $last_article = $start_article - 1;
}

print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],

@xover)),"\n";
# end script that prints 3 arts from clc



my $groups = $nntp->list();

open my $newsrc, '>', $settings{NEWSRC}
    or die "Cannot open '$settings{NEWSRC}': $!";

print $newsrc join( "!\n", sort keys %$groups );

close $newsrc
    or die "Cannot close '$settings{NEWSRC}': $!";
# Disconnect from the NNTP server
$nntp->quit;


#  perl mats3.pl 2>text50.txt >text51.txt
__END__


-- 
"A belief in a supernatural source of evil is not necessary; men alone
are quite capable of every wickedness."

~~  Joseph Conrad (1857-1924), novelist 

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads