#!/usr/bin/perl #### #### Copyright (c) 2004 Michael McDonnell and Winterstorm Solutions, Inc. #### #### You may redistribute and modify this program under the terms of the GNU GPL 2.0. #### #### Purpose: show the last 20 DVDs added to (SIRSI Unicorn) catalogue #### Usage: run from the command line; output goes to standard out #### Notes: This is the crappy version. A documented, reusable version will follow. #### #### Special Thanks to Peter Binkley for explaining the idiosynracies of SIRSI #### Unicorn. #### use strict; use Net::Z3950; use MARC::Record; use XML::RSS; use Time::Piece::ISO; # overrides localtime() to provide ISO8601 time # Base URL to peform a search for a specific item in the catalogue through the ipac. my $search_url= 'http://sirsiweb/uhtbin/cgisirsi/x/0/57/5?user_id=MAGIC&searchdata1='; # establish the z39.50 connection my $server = 'sirsiserver'; my $port = 2200; my $database = 'unicorn'; # figure out what we are searching for my $term = 'VIDEORECORDING'; # could try DVD or VIDEOCASSETTE my $search = sprintf('@attr 1=1016 "%s"', $term); my $recordsyntax = 'USMARC'; my $latest_count = 20; # connect to Z39.50 server my $conn = new Net::Z3950::Connection($server, $port, 'databaseName' => $database, 'preferredRecordSyntax' => $recordsyntax ); unless(defined $conn) { print STDERR "Connection Failed\n"; exit 2; } # perform search my $rs = $conn->search($search); unless(defined $rs) { print STDERR $conn->errmsg() . "\n"; exit 1; } # create rss my $rss = new XML::RSS('version' => '1.0'); my $channel_link = 'http://sirsiweb/uhtbin/cgisirsi/x/0/57/5?user_id=MAGIC&searchdata1=VIDEORECORDING'; my $channel_creator = 'Michael McDonnell (mailto:michael@winterstorm.ca)'; my $channel_title = 'Latest Videos in Catalogue'; my $channel_desc = <channel( 'title' => $channel_title, 'link' => $channel_link, 'description' => $channel_desc, syn => { updatePeriod => 'hourly', updateFrequency => 1, updateBase => '2004-01-01T00:00+00:00', }, dc => { 'title' => $channel_title, 'creator' => $channel_creator, 'subject' => 'videorecording,library,dvd,vhs', 'description' => $channel_desc, 'date' => localtime(), 'publisher' => $channel_creator, 'contributor' => 'The Library', 'type' => 'Collection', 'format' => 'text/html', 'identifier' => $channel_link, 'source' => sprintf('z39.50s://%s:%i/%s?%s&rs=%s', $server, $port, $database, $term, $recordsyntax), 'coverage' => "Latest $latest_count Videos added to catalogue", 'rights' => 'http://creativecommons.org/licenses/sa/1.0/', 'created' => '2004-04-21T11:00:11-07:00', 'modified' => localtime(), 'extent' => "$latest_count videorecordings", 'language' => 'en-CA' }, ); my ($link, $subject, $creator, $publisher, $date, $title, $actors, $format, $identifier, $description); my $num = 0; my $i = 0; my($rec, $marcrec, $status) = undef; my $lastrec = $rs->size() < $latest_count ? $rs->size() : $latest_count; # prefetch up to $lastrec records; this is more effecient $rs->present(1,$lastrec); foreach $i (1..$lastrec) { # FIXME no error checking for retrieval of record $marcrec = MARC::Record->new_from_usmarc($rs->record($i)->rawdata()); if($marcrec) { $subject = $marcrec->field('650') ? $marcrec->field('650')->as_string() : undef; $creator = $marcrec->author(); $publisher = $marcrec->field('028') ? $marcrec->field('028')->as_string() : undef; $date = $marcrec->publication_date(); $identifier = $marcrec->field('035') ? $marcrec->field('035')->as_string() : $marcrec->field('020') ? $marcrec->field('020')->as_string() : undef; $title = $marcrec->field('245') ? $marcrec->field('245')->as_string('abnp') : undef ; $link = sprintf('%s%s', $search_url, &plus_to_space($identifier) ); ($num, $format) = split(/ /, $marcrec->field('300') ? $marcrec->field('300')->as_string('a') : undef) ; $format =~ s/s$//i; $description = sprintf('%s by %s; %s from %s; %s; %s', $title, $creator, $date, $publisher, $subject, $marcrec->field('300') ? $marcrec->field('300')->as_string() : '') ; $rss->add_item( 'title' => $title, 'link' => $link, 'description' => $description, dc => { 'title' => $title, 'creator' => $creator, 'subject' => $subject, 'description' => $description, 'date' => $date, 'publisher' => $publisher, 'contributor' => $actors, 'type' => 'videorecording', 'format' => $format, 'identifier' => $identifier, 'relation' => $link, # 'audience' => 'adult or child', # 'created' => 'marc record creation', # 'modified' => 'marc record update', # 'language' => 'languages' } ); } else { print STDERR $rec->render(); } } $conn->close(); print $rss->as_string(); sub plus_to_space { my $string = shift; $string =~ tr| |+|; return $string; }