version 1.3, 2005/11/17 22:34:49
|
version 1.8, 2005/11/25 21:18:35
|
Line 404 sub make_new_child {
|
Line 404 sub make_new_child {
|
} |
} |
} else { |
} else { |
# Do an sql query |
# Do an sql query |
$result = &do_sql_query($query,$arg1,$arg2); |
$result = &nsdl_query($query,$arg1,$arg2); |
} |
} |
# result does not need to be escaped because it has already been |
# result does not need to be escaped because it has already been |
# escaped. |
# escaped. |
Line 420 sub make_new_child {
|
Line 420 sub make_new_child {
|
exit; |
exit; |
} |
} |
} |
} |
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
|
|
|
=item &do_sql_query |
|
|
|
Runs an sql metadata table query. |
|
|
|
Inputs: $query, $custom, $customshow |
|
|
|
Returns: A string containing escaped results. |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
{ |
|
my @metalist; |
|
|
|
sub process_file { |
|
if ( -e $_ && # file exists |
|
-f $_ && # and is a normal file |
|
/\.meta$/ && # ends in meta |
|
! /^.+\.\d+\.[^\.]+\.meta$/ # is not a previous version |
|
) { |
|
push(@metalist,$File::Find::name); |
|
} |
|
} |
|
|
|
sub do_sql_query { |
|
my ($query) = @_; |
|
&logthis('doing query '.$query); |
|
|
|
my @results = (); |
|
|
|
# |
|
if ($query) { |
|
#prepare and execute the query |
|
my $aref=&nsdl_query($query); |
|
foreach my $row (@$aref) { |
|
my @b=map { &escape($_); } @$row; |
|
push @results,join(",", @b); |
|
} |
|
|
|
} |
|
return join("&",@results); |
|
} # End of &do_sql_query |
|
|
|
} # End of scoping curly braces for &process_file and &do_sql_query |
|
######################################################## |
|
######################################################## |
######################################################## |
|
|
=pod |
=pod |
Line 845 sub HUPSMAN { # sig
|
Line 793 sub HUPSMAN { # sig
|
# |
# |
# Takes SQL query |
# Takes SQL query |
# sends it to NSDL |
# sends it to NSDL |
# has to return array reference |
|
# |
# |
|
|
sub nsdl_query { |
sub nsdl_query { |
my $query=shift; |
my $query=shift; |
my ($keyword)=($query=~/\"\%([^\%]+)\%\"/); |
my ($keyword)=($query=~/\"\%([^\%]+)\%\"/); |
$keyword=&escape($keyword); |
$keyword=&escape($keyword); |
&logthis('Doing '.$keyword); |
my $url='http://search.nsdl.org?verb=Search&s=0&n=500&q=-link.primaryCollection:oai\:nsdl.org\:nsdl.nsdl\:00254%20'.$keyword; |
my $url='http://search.nsdl.org?verb=Search&s=0&n=500&q='.$keyword; |
|
my $ua=new LWP::UserAgent; |
my $ua=new LWP::UserAgent; |
my $response=$ua->get($url); |
my $response=$ua->get($url); |
|
my $parser=HTML::LCParser->new(\$response->content); |
return []; |
my $is=''; |
|
my $cont=''; |
|
my $token; |
|
my %result=(); |
|
my $allresults=''; |
|
while ($token=$parser->get_token) { |
|
if ($token->[0] eq 'T') { |
|
$cont.=$token->[1]; |
|
} elsif ($token->[0] eq 'S') { |
|
if ($token->[1] eq 'record') { |
|
%result=(); |
|
} elsif ($token->[1]=~/^dc\:/) { |
|
$is=$token->[1]; |
|
$cont=''; |
|
} |
|
} elsif ($token->[0] eq 'E') { |
|
if ($token->[1] eq 'record') { |
|
# |
|
# Now store it away |
|
# |
|
my $url=$result{'dc:identifier'}; |
|
if ($url=~/^http\:/) { |
|
$url=~s/^http:\//\/ext/; |
|
} else { |
|
$url=''; |
|
} |
|
if ($url) { |
|
my ($mime)=($url=~/\.(\w+)$/); |
|
$mime=~tr/A-Z/a-z/; |
|
$allresults.='&'. |
|
&escape($result{'dc:title'}).','. |
|
&escape($result{'dc:creator'}).','. |
|
&escape($result{'dc:subject'}).','. |
|
&escape($url).',,,,'. |
|
&escape($result{'dc:description'}).','. |
|
&escape($mime).',seniso,,,,public,nsdl,,,,,,,,,,,,,,,,,,,,,,,,,,,,'; |
|
} |
|
%result=(); |
|
} elsif ($token->[1]=~/^dc\:/) { |
|
$result{$is}=$cont; |
|
} |
|
} |
|
} |
|
$allresults=~s/^\&//; |
|
&logthis($allresults); |
|
return $allresults; |
} |
} |
|
|
=pod |
=pod |