🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #23501

Re: slrn score-file fiddling

#23501
From: Christopher B. Browne
Date: Sat, 29 Jun 1996 00:00
84 lines
2964 bytes
It's bad form to follow-up yourself; there were some ugly bugs in the Perl
script.  (well, fairly ugly.  Colons in data were being interpreted as
data separators.  Ick.)

- Limitations
  - Can't have multiple "subject:" lines for a particular score.
  - Ignores expiry date

Otherwise, it nicely cleans up any automatically generated score files.


#!/usr/bin/perl
# Reformat score file
open(SCORES, "</home/cbbrowne/News/scores/Scores");

while (<SCORES>) {
    if (/^%/) {
	# Skip comment line
    } else {
	if (/\s*Score:(.*)\s*/) {
	    $score = $1;
	}
	if ((/^\s*\[/) || (/^\s*Score:/ )) {
	    # New entry
	    # Process last entry
	    # Clear from/to/sub/score/xref/newsgroup
	    $key = "$group\t$exp\t$from\t$ref\t$sub\t$xref\t$grp";
	    $RULE{$key} += $score;
	    ($exp, $from, $sub, $xref, $grp) = ();
	}
        if (/\s*\[(.*)\]\s*$/) {
	    $group = $1;
	} elsif (/\s*Expires:(.*)\s*/) {
	    $exp = $1;
	} elsif (/\s*Subject:(.*)\s*/) {
	    $sub = $1;
	} elsif (/\s*Newsgroup:(.*)\s*/) {
	    $grp = $1;
	} elsif (/\s*References:(.*)\s*/) {
	    $ref = $1;
	} elsif (/\s*From:(.*)\s*$/) {
	    $from = $1;
	} elsif (/\s*Xref:(.*)\s*$/) {
	    $xref = $1;
	}
    }
}

# toss in a rule guaranteed to fall in at the end so that we get the
# final score dumped out.
foreach $i (sort keys %RULE) {
    $score = $RULE{$i};
    if ($score < -9999) {
	$score = -9999;
    }
#    print $i, $score, "\n";
    ($group, $exp,$from,$ref,$sub,$xref,$grp) = split(/\t/, $i);
    if (/\t\t\t\t\t\t/) {
	# Don't do it - no data!
    } else {
	if ($group eq $lastgroup) {
	    # Skip group - hasn't changed
	} else {
	    $lastgroup = $group;
	    print "\[$group\]\n";
	}
	print "Score: $score\n";
	print "\tExpires: $exp\n" unless $exp eq "";
	print "\tSubject: $sub\n" unless $sub eq "";
	print "\tNewsgroup: $grp\n" unless $grp eq "";
	print "\tReferences: $ref\n" unless $ref eq "";
	print "\tFrom: $from\n" unless $from eq "";
	print "\tXref: $xref\n" unless $xref eq "";
	print "\n";
    }
}

-- 
Christopher B. Browne, cbbrowne@conline.com, chris_browne@sdt.com
Web: http://www.conline.com/~cbbrowne  SAP Basis Consultant, UNIX Guy,
Linux Guy.  "Windows?  Ah...  The Athena Project from MIT..."


Technical Details
Message-ID: <slrn4taonq.861.cbbrowne@dantzig.nodomain.nowhere>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <slrn4tal8o.7v4.cbbrowne@dantzig.nodomain.nowhere>

Show Full Headers
Complete Article Headers
Message-ID: <slrn4taonq.861.cbbrowne@dantzig.nodomain.nowhere>
Subject: Re: slrn score-file fiddling
Date: Sat, 29 Jun 1996 00:00:00 +0000
From: cbbrowne@dantzig.nodomain.nowhere (Christopher B. Browne)
References: <slrn4tal8o.7v4.cbbrowne@dantzig.nodomain.nowhere>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 162802170
Organization: UniComp Technologies International Corp -- Internet Service
Reply-to: cbbrowne@conline.com
Newsgroups: news.software.readers