Article View: news.software.nntp
Article #36715Re: Creating a newsgroups description file (was Re: newsgroups file)
From: Arthur Hagen
Date: Sat, 17 Apr 1999 00:00
Date: Sat, 17 Apr 1999 00:00
127 lines
4846 bytes
4846 bytes
In article <7f9l34$k0o$1@east44.supernews.com>, Jeremy <jeremy@exit109.com> writes:
> Brad Knowles <brad@shub-internet.org> wrote:
>
> >> Someday I'll get around to that. Hmm, maybe I'll do that this week.
> >
> > So, where is the code? I want to see some code, dammit! ;-)
>
> Here ya go. It's quick, it's dirty, it's barely tested, but it just
> worked for me. :)
>
> #!/usr/local/bin/perl
> #
> # mkngfile - make a newsgroup description file from multiple sources
Good one. I have a much simpler one that will make one
"newsgroups.full" file in addition to the newsgroups file. The
newsgroups file will be shortened to only contain the groups that are
in your active file, and the newsgroups.full file will keep the newest
entry for any newsgroup, whether you carry it or not. That saves a lot
of time for the clients that fetches the newsgroups file, and allows
you to add in the new descriptions if you add new newsgroups. If
anything is changed in or added to the newsgroups file, it takes
precedence over similar entries in the newsgroups.full file, so you can
still run docheckgroups and similar, and run this script afterwards
without losing anything. Saving 30 seconds for every client that
pulls the newsgroups file is nice :-)
Anyhow, here's the script. Add locking and moving the new files
in place automatically if you need it.
Forgive me for committing bad perl.
--- cut here ---
#!/bin/perl
# cleannewsgroups.pl
# Copyright 1997-1999 Arthur Hagen
# This program is Freeware. It's not GPL or Public Domain.
require 5.0;
$DEBUG=1;
# Change the path below!
$dbdir = '/usr/local/news/db';
chdir($dbdir)
or die "Can't cd to '$dbdir'\n";
my %ng;
my @groups;
print "Reading active ...\n" if $DEBUG;
open(INFILE,'<active')
or die "Cant find active file in '$dbdir'\n";
while (<INFILE>) {
my ($group,@rest) = split;
push @groups,$group;
}
print "Reading newsgroups ...\n" if $DEBUG;
open(INFILE,'<newsgroups')
or die "Can't find newsgroups file in '$dbdir'\n";
while (<INFILE>) {
chomp;
my ($group,@rest) = split /\t/;
my $desc = $rest[-1]; # Only the last entry, no need for extra tabs.
# Remove duplicate (Moderated) comments
while ($desc =~ s/\(Moderated\)(\s)+\(Moderated\)/(Moderated)/g)
{};
# Strip trailing spaces too
$desc =~ s/(\s)+$//;
$ng{$group} = $desc;
}
close INFILE;
print "Reading newsgroups.full ...\n" if $DEBUG;
if (open(INFILE,'<newsgroups.full')) {
# No harm done if there aren't any newsgroups.full file. It will
# be created later.
while (<INFILE>) {
chomp;
my ($group,@rest) = split /\t/;
# Let newsgroups take precedence over newsgroups.full
unless ($ng{$group}) {
my $desc = $rest[-1];
while ($desc =~ s/\(Moderated\)(\s)+\(Moderated\)/(Moderated)/g)
{};
$desc =~ s/(\s)+$//;
$ng{$group} = $desc;
}
}
close INFILE;
}
# Remove this part if you want your newsgroups file to be in the same
# order as your active file. I prefer both to be sorted.
print "Sorting groups ...\n" if $DEBUG;
my @groupss = sort @groups;
print "Writing newsgroups.full.n ...\n" if $DEBUG;
open(OUTFILE,'>newsgroups.full.n');
foreach $group (sort keys %ng) {
# One tab is enough. Pretty-printing is for humans, not machines.
print OUTFILE $group,"\t",$ng{$group},"\n";
}
close OUTFILE;
print "Writing newsgroups.n ...\n" if $DEBUG;
open(OUTFILE,'>newsgroups.n');
my $numgroups = scalar @groupss;
for ($i=0;$i<$numgroups;$i++) {
my $group = $groupss[$i];
if (my $desc = $ng{$group}) {
print OUTFILE $group,"\t",$desc,"\n";
}
}
close OUTFILE;
print "Done.\n" if $DEBUG;
exit 0;
--- cut here ---
Regards,
--
*Art
Technical Details
Message-ID:
<lrcaf7.7at3.ln@flying.broomstick.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<3714C953.5B0555C1@online.be> <877lresn86.fsf@slip-32-100-202-51.ma.us.ibm.net> <7f3hm5$hfm$1@east44.supernews.com> <brad-1504991106480001@brad.techos.skynet.be> <7f9l34$k0o$1@east44.supernews.com>Show Full Headers
Complete Article Headers
Message-ID: <lrcaf7.7at3.ln@flying.broomstick.com> Subject: Re: Creating a newsgroups description file (was Re: newsgroups file) Date: Sat, 17 Apr 1999 00:00:00 +0000 From: art@flying.broomstick.com (Arthur Hagen) References: <3714C953.5B0555C1@online.be> <877lresn86.fsf@slip-32-100-202-51.ma.us.ibm.net> <7f3hm5$hfm$1@east44.supernews.com> <brad-1504991106480001@brad.techos.skynet.be> <7f9l34$k0o$1@east44.supernews.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 467669921 X-Complaints-To: abuse@broomstick.com X-Trace: kether.broomstick.com 924367266 55285 194.52.172.70 (17 Apr 1999 16:41:06 GMT) Organization: Broomstick Net Services Reply-To: art@broomstick.com NNTP-Posting-Date: 17 Apr 1999 16:41:06 GMT Newsgroups: news.software.nntp