root / updategroups.pl @ 2

View | Annotate | Download

1
#!/usr/bin/perl -w
2
3
use strict;
4
use News::NNTPClient;
5
6
my $f = "groups.conf";
7
my $a = "active";
8
my $n = "newsgroups";
9
my $ActiveTimesFromLastServer = 1;
10
11
my $debug = 0;
12
my %groups;
13
my %descrs;
14
my %times;
15
16
sub getgroups {
17
    my ($pat, $server) = @_;
18
19
    my $c = new News::NNTPClient($server);
20
    die "Could not connect\n" if ! $c;
21
22
    foreach ( $c->list('active',$pat) ) {
23
	chop;
24
	print $c->code .' '. $c->message if $c->code !~ /2../ && $debug; 
25
	my ($group,undef) = split;
26
	next if $groups{$group};
27
	$groups{$group} = "$_ $server";
28
    }
29
30
    foreach ( $c->list('newsgroups',$pat) ) {
31
	chop;
32
	print $c->code .' '. $c->message if $c->code !~ /2../ && $debug; 
33
	my ($group,undef) = split;
34
	next if $descrs{$group};
35
	$descrs{$group} = $_;
36
    }
37
38
    if ( ! $ActiveTimesFromLastServer ) {
39
	foreach ( $c->list('active.times') ) {
40
	    chop;
41
	    print $c->code .' '. $c->message if $c->code !~ /2../ && $debug; 
42
	    my ($group,$time,undef) = split;
43
	    $times{$group} = $time;
44
	}
45
    }
46
47
    $c->quit();
48
}
49
50
my $lastserver = "";
51
52
# read groups.conf and load each entry
53
open(F,$f) || die "open $f $!\n";
54
while(<F>){
55
    next if ( m/^$/g || m/^#/g || m/^;/g );
56
    my ($pat,$server) = split;
57
    getgroups($pat,$server);
58
    $lastserver = $server;
59
}
60
close F;
61
62
if ( $ActiveTimesFromLastServer ) {
63
    my $c = new News::NNTPClient($lastserver);
64
    die "Could not connect\n" if ! $c;
65
    foreach ( $c->list('active.times') ) {
66
	chop;
67
	print $c->code .' '. $c->message if $c->code !~ /2../ && $debug; 
68
	my ($group,$time,undef) = split;
69
	$times{$group} = $time;
70
    }
71
    $c->quit();
72
}
73
74
# write semi-active file
75
open(F,">$a") || die "open $a $!\n";
76
foreach ( keys %groups ) {
77
    $times{$_} = 0 if ! defined $times{$_};
78
    print F $groups{$_} ." ". $times{$_} ."\n";
79
}
80
close F;
81
82
# write newsgroups file
83
open(F,">$n") || die "open $n $!\n";
84
foreach ( keys %descrs ) {
85
    print F $descrs{$_} ."\n";
86
}
87
close F;