--- nsdl/nsdlloncapaorg/harvester.pl 2003/07/28 20:14:17 1.2 +++ nsdl/nsdlloncapaorg/harvester.pl 2003/10/21 15:58:26 1.7 @@ -12,6 +12,9 @@ use strict; use LWP::UserAgent; use Getopt::Std; use Digest::MD5 qw(md5_hex); +use IO::File; + +my $basepath='/home/httpd/cgi-bin/OAI-XMLFile/XMLFile/nsdlexport/data'; my $pub_month; my $pub_year; @@ -25,10 +28,29 @@ my $content_regex = 'File Not Found'; # Configuration my $debug = 0; -my $url = 'http://s10.lite.msu.edu/cgi-bin/metadata_harvest.pl'; + # The list of servers is from the LON-CAPA CVS repository in /loncapa/loncom/production_hosts.tab -my @servers = ( 'newscience.westshore.cc.mi.us', 's10.lite.msu.edu', 's12.lite.msu.edu', 'lon-capa.chem.sunysb.edu', 'schubert.tmcc.edu', 'dalton.chem.sfu.ca', 'capa2.phy.ohiou.edu', 'pollux.physics.fsu.edu', 'loncapa.physics.sc.edu', 'loncapa.math.ucf.edu', 'zappa.ags.udel.edu', 'loncapa.gwu.edu'); +my @servers = ( +'newscience.westshore.cc.mi.us', +'s10.lite.msu.edu', +'s12.lite.msu.edu', +'lon-capa.chem.sunysb.edu', +'schubert.tmcc.edu', +'dalton.chem.sfu.ca', +'capa2.phy.ohiou.edu', +'pollux.physics.fsu.edu', +'loncapa.physics.sc.edu', +'loncapa.math.ucf.edu', +'zappa.ags.udel.edu', +'loncapa.gwu.edu', +'neptune.physics.ndsu.nodak.edu', +'capa1.uwsp.edu', +'natasha.it.fit.edu', +'loncapa.Mines.EDU', +'loncapa.chm.nau.edu'); +foreach (@servers) { + my $url='http://'.$_.'/cgi-bin/metadata_harvest.pl'; # End Configuration my $ua = new LWP::UserAgent; @@ -40,6 +62,7 @@ $request->authorization_basic('reaper', my $response = $ua->request( $request ); if ( $response->is_success ) { + print 'SUCCESS: ' . $response->message.' for '.$url."\n\n"; $content = $response->content; # Delete all blank lines $content =~ s/(?is_success ) { # Push the content into an array @loncapa = split /\n/, $content; } else { - die 'LON-CAPA request failed: ' . $response->message; + print 'LON-CAPA request failed: ' . $response->message.' for '.$url."\n\n"; + next; } #@loncapa=undef; @@ -60,6 +84,7 @@ if ( $response->is_success ) { #} my %records = ();; + foreach my $metadata (@loncapa) { chomp $metadata; $metadata=~s/[^\w\d\s\.\;\:\,\|\/]/ /gs; @@ -82,15 +107,19 @@ foreach my $metadata (@loncapa) { next if ( ($subject eq 'Sample') || ($subject eq 'Something') ); my $resourceurl = 'http://nsdl.lon-capa.org' . $tkline[3]; my $baseid=$tkline[3]; + my ($adom,$auname)=($baseid=~/^\/res\/(\w+)\/(\w+)\//); $baseid=~s/\W/\_/g; $baseid=~s/^\_res\_//g; + my $fileid=md5_hex($baseid); next if ( $resourceurl =~ /(.*)\/demo\/(.*)/ ); my $keywords = $tkline[4]; my $version = $tkline[5]; my $notes = $tkline[6]; my $abstract = $tkline[7]; - next if ($abstract eq ''); + unless ($abstract) { $abstract=$subject; } + unless ($abstract) { $abstract=$title; } + unless ($abstract) { $abstract=$keywords; } my $type = $tkline[8]; my $learning_resource_type; if ( $type eq 'problem' ) { @@ -128,8 +157,9 @@ foreach my $metadata (@loncapa) { next if ( $language ne 'seniso'); my $primary_language='en-US'; my $creation_date = $tkline[10]; - my ($pub_year,$pub_month,$pub_day) = ( $creation_date =~ /^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/ ); + my ($pub_year,$pub_month,$pub_day) = ( $creation_date =~ /^(\d{4}) (\d{2}) (\d{2})\s(\d{2}):(\d{2}):(\d{2})$/ ); my $revision_date = $tkline[11]; + my ($rev_year,$rev_month,$rev_day) = ( $revision_date =~ /^(\d{4}) (\d{2}) (\d{2})\s(\d{2}):(\d{2}):(\d{2})$/ ); my $owner = $tkline[12]; my $rights_description; my $copyright = $tkline[13]; # public,domain,default,private (skip if private and domain) @@ -146,19 +176,35 @@ foreach my $metadata (@loncapa) { # Defaults mean access open to any registered LON-CAPA user # Private means open only to author of material next if ( $copyright eq 'private'); + next if ( $copyright eq 'domain'); my $platform = "5"; # HTML Browser (not specified but construed from metadata) - print (< - $title - $author_fname $author_lname - $keywords - $subject - $resourceurl - $primary_language - $abstract - $revision_date - - +# +# Create path +# + unless (-e $basepath.'/'.$adom) { mkdir($basepath.'/'.$adom); } + unless (-e $basepath.'/'.$adom.'/'.$auname) { + mkdir($basepath.'/'.$adom.'/'.$auname) || die 'Could not create '.$basepath.'/'.$adom.'/'.$auname; + } + open(XML,'>'.$basepath.'/'.$adom.'/'.$auname.'/'.$baseid.'.xml'); + print XML (< + + + $title + $author_fname $author_lname + $resourceurl + $keywords + $subject + $primary_language + $abstract + $rev_year-$rev_month-$rev_day + ENDMETA + close (XML); +} } -