importing newsrcs from ubh 2 into ubh 3

Adam Rice <[email protected]> Tue, 8 Jul 2003 16:05:54 +0100
Newsgroups gmane.network.ubh
Message-ID <[email protected]>
I may be re-inventing the wheel here, but I don't remember anyone posting one
previously, so here's a program to import a .newsrc from ubh2 into ubh3. To
put it another way, this program marks articles as read in the MySQL database
that were marked as read in the newsrc. This saves downloading them again when
migrating from ubh2 to ubh3. It cannot actually create article entries, so
ubhdb must be run first.

In order to get the message IDs, this program also needs the UBH 2 cachefile.
Example usage:

./ubhdb
./import-newsrc alt.binaries.pictures.aviation /home/me/ubh/newsrc \
   /home/me/ubh/cache/news.myisp.com-alt.binaries.pictures.aviation.ubhcache

This program is works-for-me-ware, and as such has a few rough edges. In
particular, it will only work if run from the directory where ubh3 is
installed.

There's currently no way to migrate back from ubh3 to ubh2. Of course, if I
find I need to do so, I may come up with one :-)

Adam

-- 
Adam Rice -- [email protected] -- Blackburn, Lancashire, England

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Coral Calcium for Greater Health - $23.95
http://www.challengerone.com/t/l.asp?cid=2805&lp=calcium2.asp
http://us.click.yahoo.com/MmkSQC/NTVGAA/ySSFAA/IHFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
import-newsrc (text/plain, 1.2 KB)
#!/usr/local/bin/perl -w

# import-newsrc
# uses a newsrc and cachefile from ubh 2 to mark articles as read in a ubh 3 MySQL database
# ubhdb must be run first to download the headers!

# Copyright 2003 by Adam Rice. This program is free
# software; you can redistribute it and/or modify it under the same
# terms as Perl itself.

use strict;

BEGIN {
    push @INC, './lib';
}

use Ubh::DB;
use News::Newsrc;

if (@ARGV!=3) {
    die "Usage: $0 <newsgroup> <newsrc> <cachefile>\n";
}

my($group, $newsrc, $cachefile) = @ARGV;

my $rc = new News::Newsrc;

$rc->load($newsrc)
  || die "Couldn't load $newsrc ($!)\n";

my $dbh = Ubh::DB::connect();
my $sth = $dbh->prepare("update headers set status='READ' where msgid=?");
if (!$sth) {
    die "Error in prepare:" . $dbh->errstr . "\n";
}

my($marked) = 0;

open(CACHEFILE, $cachefile)
  || die "Couldn't open $cachefile for reading ($!)\n";
while (<CACHEFILE>) {
    my($id, $number) = split(/\|/, $_);
    if ($rc->marked($group, $number)) {
	if (!$sth->execute($id)) {
	    die "Error in UPDATE while trying to mark read article id $id (number $number):\n",
	      $sth->errstr . "\n";
	}
	++$marked;
    }
}
close(CACHEFILE);

print "$marked articles marked as read\n";