🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #219487

perl clients and a newsgroup list

#219487
From: 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 

Technical Details
Message-ID: <1208476119_34@news.newsgroups.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!news-out.newsgroups.com!sp12lax.superfeed.net!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <1208476119_34@news.newsgroups.com>
Subject: perl clients and a newsgroup list
Date: Thu, 17 Apr 2008 18:56:01 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!news-out.newsgroups.com!sp12lax.superfeed.net!not-for-mail
Lines: 99
Organization: Newsgroups.com
Newsgroups: news.software.readers
X-Proxy-User: $$s_iz$n-74p
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Report: Please report illegal or inappropriate use to
 <abuse@newsgroups.com>. Forward a copy of ALL headers INCLUDING the body. (DO
 NOT SEND ATTACHMENTS)
X-Comments2: IMPORTANT: Newsgroups.com does not condone, support,
 nor tolerate spam or any illegal or copyrighted postings.
X-Comments: This message was posted through Newsgroups.com
X-Original-Bytes: 4400
X-Original-Lines: 117