#!/usr/bin/perl -w ###----------------------------------------------------------- ### dvd2rss.pl ### ### version 1.0 - August 30, 2004 - Peter Rukavina ### ### Connects to a Dynix(tm) web-based library OPAC and ### retrieves a list of new DVDs in the catalogue. ### Easy to modify for other purposes (basically any ### search result) with some tweaks of the search URL. ### ### Attribution-NonCommercial-ShareAlike 2.0 ### http://creativecommons.org/licenses/by-nc-sa/2.0/ ### Reinvented Inc. ###----------------------------------------------------------- use strict; use LWP::Simple; use HTML::TreeBuilder; use XML::RSS; ###----------------------------------------------------------- ### Set up some initial values that we'll use later... ###----------------------------------------------------------- my $library = "PEI Provincial Library"; # Name of library; used in the RSS feed title. my $title = "New DVDs"; # Title of the search; used the the RSS feed title. my $descrip = "A list of new DVDs at the library"; # Description of the search; used to describe the RSS feed. my $opacurl = "http://142.176.41.205/ipac20/ipac.jsp"; # Base URL of the Dynix OPAC my $search = "dvd+video"; # Search term (we use dvd+video to search for DVDs; presumably you could change this to anything) my $rssfile = "/www/htdocs/rss/dvd.xml"; # Location of the resulting RSS file. my $howmany = 25; # How many results to return ###----------------------------------------------------------- ### Construct a search URL ###----------------------------------------------------------- my $url = $opacurl . "?npp=$howmany&ipp=20&profile=pac&aspect=basic_search&term=$search&index=GW&uindex=&oper=&ri=1&menu=search&sort=1100031&source=142.176.41.205%40%21pls&go_sort_limit.x=6&go_sort_limit.y=7&limit="; ###----------------------------------------------------------- ### Start a new RSS file ###----------------------------------------------------------- my $rss = new XML::RSS(version => '0.91'); $rss->channel( title => $title . " at " . $library, link => $url, description => $descrip, ); ###----------------------------------------------------------- ### Grab the Items Out page and parse it ###----------------------------------------------------------- my $page = get( $url ) or die $!; my $p = HTML::TreeBuilder->new_from_content( $page ); # The titles of the items out are styed with a 'mediumBoldAnchor' class my @links = $p->look_down( _tag => 'a', class => 'mediumBoldAnchor' ); for my $link (@links) { my %dvd; my $dvdparent; $dvd{url} = $link->attr("href"); $dvdparent = $link->parent(); $dvd{title} = $dvdparent->as_trimmed_text; $dvd{title} =~ s/ \///; $rss->add_item( title => $dvd{title}, link => $dvd{url}, description => $dvd{title} ); } $p = $p->delete; # don't need it anymore ###----------------------------------------------------------- ### Save the RSS file and exit. ###----------------------------------------------------------- $rss->save($rssfile); ###---- The End.