Catalog

 view release on metacpan or  search on metacpan

bin/convert_dmoz.PL  view on Meta::CPAN

use Config;
use File::Basename qw(basename dirname);
chdir(dirname($0));
($file = basename($0)) =~ s/\.PL$//;
$file =~ s/\.pl$//
	if ($Config{'osname'} eq 'VMS' or
	    $Config{'osname'} eq 'OS2');  # "case-forgiving"
open OUT,">$file" or die "Can't create $file: $!";
chmod(0755, $file);
print "Extracting $file (with variable substitutions)\n";

print OUT <<"!GROK!THIS!";
$Config{'startperl'} -w

!GROK!THIS!

print OUT <<'!NO!SUBS!';

use strict;
use vars qw($create $catid_max $record_max %path2catid %catid2path 
	    %stats $verbose $today $exclude);
use Carp;
use POSIX qw(strftime);
use Getopt::Long;
use Catalog::tools::tools;
use Catalog::tools::cgi;

sub main {
    my($what);
    my($load);

    GetOptions("verbose+" => \$verbose,
	       "what=s" => \$what,
	       "load=s" => \$load,
	       "exclude=s" => \$exclude);

    my($input) = @ARGV;

    if(!defined($input) ||
       ! -r $input) {
	print STDERR "
usage: $0 [-v] [-exclude pattern] -what {content|structure} {content.rdf[.gz]|structure.rdf[.gz]}
       $0 [-v] -load all directory
       $0 [-v] -load {category|entry2category|category2category|dmozrecords} file.txt
";
	return;
    }

    $| = 1;

    convert($what, $input) if($what);
    load($load, $input) if($load);

    stats();
}

sub load {
    my($what, $input) = @_;
    my($all) = $what eq 'all';
    my($dir) = $input;

    $input = "$dir/category.txt" if($all);
    if($all || $what eq 'category') {
	system("mysql -e \"delete from catalog_category_dmoz where rowid > 1;\" dmoz");
	system("mysql -e \"load data infile '$input' into table catalog_category_dmoz;\" dmoz");
	system("echo catalog_category_dmoz; mysql -e \"select count(*) from catalog_category_dmoz;\" dmoz");
    } 

    $input = "$dir/entry2category.txt" if($all);



( run in 0.828 second using v1.01-cache-2.11-cpan-d8267643d1d )