#!/usr/bin/perl -w # champRSS - converts an RSS file(s) to HTML # It takes three arguments, a sport, an affiliate id, and a format type. # # by Daniel Bergan, Bergan Consulting (www.berganconsulting.com) # Copyright (c) 2004 Bergan Consulting. All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # INCLUDES use strict; use XML::RSS; use LWP::Simple; # Declare variables my $content; my $sportNo; my $url; my $sportName; my $fileName; # MAIN # check for command-line arguments die "Usage: champRSS.pl sport, affiliate id, and format type ('s' - single page listing all items | 'm' - link page and multiple pages showing each item on a separate page)\n" unless @ARGV == 3; # get the command-line argument my $sport = shift; my $affiliate = shift; my $format = shift; # create new instance of XML::RSS my $rss = new XML::RSS; # argument is a URL if ($sport =~ /athletic director/i) { #Atheletic Director $sportNo = 105; $sportName = "Atheletic Director"; $fileName = "athleticdirector.html"; } elsif ($sport =~ /band/i) { #Band Director $sportNo = 111; $sportName = "Band Director"; $fileName = "banddirector.html"; } elsif ($sport =~ /baseball/i) { #Baseball $sportNo = 70; $sportName = "Baseball"; $fileName = "baseball.html"; } elsif ($sport =~ /basketball/i) { #Basketball $sportNo = 69; $sportName = "Basketball"; $fileName = "basketball.html"; } elsif ($sport =~ /cheer/i) { #Cheerleading $sportNo = 81; $sportName = "Cheerleading & Dance Team"; $fileName = "cheerleading.html"; } elsif ($sport =~ /field hockey/i) { #ield Hockey $sportNo = 113; $sportName = "Field Hockey"; $fileName = "fieldhockey.html"; } elsif ($sport =~ /football/i) { #Football $sportNo = 71; $sportName = "Football"; $fileName = "football.html"; } elsif ($sport =~ /general|all/i) { #all sports (general featured items) $sportNo = -100; $sportName = "Featured Items"; $fileName = "championship.html"; } elsif ($sport =~ /golf/i) { #Golf $sportNo = 80; $sportName = "Golf"; $fileName = "golf.html"; } elsif ($sport =~ /gymnastics/i) { #Gymnastics $sportNo = 115; $sportName = "Gymnastics"; $fileName = "gymnastics.html"; } elsif ($sport =~ /hockey/i) { #Hockey $sportNo = 101; $sportName = "Hockey"; $fileName = "hockey.html"; } elsif ($sport =~ /lacrosse/i) { #Lacrosse $sportNo = 114; $sportName = "Lacrosse"; $fileName = "lacrosse.html"; } elsif ($sport =~ /train/i) { #Personal Training $sportNo = 124; $sportName = "Personal Training"; $fileName = "training.html"; } elsif ($sport =~ /education/i) { #Physical Eductaion $sportNo = 118; $sportName = "Physical Eductaion"; $fileName = "pe.html"; } elsif ($sport =~ /soccer/i) { #Soccer $sportNo = 75; $sportName = "Soccer"; $fileName = "soccer.html"; } elsif ($sport =~ /softball/i) { #Softball $sportNo = 72; $sportName = "Softball"; $fileName = "softball.html"; } elsif ($sport =~ /swim/i) { #Swimming $sportNo = 102; $sportName = "Swimming"; $fileName = "swimming.html"; } elsif ($sport =~ /tennis/i) { #Tennis $sportNo = 78; $sportName = "Tennis"; $fileName = "tennis.html"; } elsif ($sport =~ /track/i) { #Track & Field $sportNo = 73; $sportName = "Track & Field"; $fileName = "track.html"; } elsif ($sport =~ /triathlon/i) { #Triathlon $sportNo = 126; $sportName = "Triathlon"; $fileName = "triathlon.html"; } elsif ($sport =~ /volleyball/i) { #Volleyball $sportNo = 74; $sportName = "Volleyball"; $fileName = "volleyball.html"; } elsif ($sport =~ /polo/i) { #Water Polo $sportNo = 112; $sportName = "Water Polo"; $fileName = "waterpolo.html"; } elsif ($sport =~ /wrestl/i) { #Wrestling $sportNo = 79; $sportName = "Wrestling"; $fileName = "wrestling.html"; } else { die "Please enter a valid sport.\n"; } $affiliate = "rss" unless defined($affiliate); $format = "s" unless defined($format); $url = "http://www.championshipproductions.com/cgi-bin/champ/rss.xml?sport=$sportNo&affiliate=$affiliate"; $content = get($url); die "Could not retrieve $url" unless $content; # parse the RSS content $rss->parse($content) or die "cannot parse XML file"; # Parse it; # print the HTML channel (single file) if ($format =~ /s/i) { #Open File open FILE, ">".$fileName or die "Cannot Open File: $fileName"; #****************************************** #HTML # change this for your web site #****************************************** # Start displaying the HTML result. Use a stylesheet to make it look good, or modify as needed. print FILE "$rss->{'channel'}->{'description'}"; #print the channel description as a link to the channel link print FILE "

{'channel'}->{'link'}\" title=\"$rss->{'channel'}->{'description'}\">"; #If there is an image, print it if ($rss->{'image'}->{'url'}) { print FILE "{'image'}->{'url'}\" border=0 alt=\"$rss->{'channel'}->{'description'}\">"; } print FILE "$rss->{'channel'}->{'title'}"; print FILE "

\n"; print FILE "\n"; # Print each item foreach my $item (@{$rss->{'items'}}) { next unless defined($item->{'title'}) && defined($item->{'link'}); print FILE "

\n"; #print a link to an item print FILE "{'link'}\" title=\"$item->{'title'}\">\n"; #If there is a thumbnail image, print it if ($item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'thumbURL'}) { print FILE "{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'thumbURL'}\" alt=\"$item->{'title'}\" border=0>  "; } #print the item title print FILE "$item->{'title'}\n"; print FILE "

\n"; #print the item description print FILE "$item->{'description'}
\n"; #print the price and the buy now link print FILE "\$$item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'price'}   {'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'buynowURL'}\">Buy Now at ChampionshipProductions.com!\n"; print FILE "

\n"; } print FILE "\n"; print FILE "\n"; } else { # print the HTML channel (multiple files) #Open Link file open FILE, ">championship.html" or die "Cannot Open File: championship.html"; #Write the link html page print FILE "$rss->{'channel'}->{'description'} \n"; #print the channel description as a link to the channel link print FILE "

{'channel'}->{'link'}\" title=\"$rss->{'channel'}->{'description'}\">"; #If there is an image, print it if ($rss->{'image'}->{'url'}) { print FILE "{'image'}->{'url'}\" border=0 alt=\"$rss->{'channel'}->{'description'}\">"; } print FILE "$rss->{'channel'}->{'title'}"; print FILE "

\n"; print FILE "\n"; print FILE "\n"; my $item_url; foreach my $item (@{$rss->{'items'}}) { next unless defined($item->{'title'}) && defined($item->{'link'}); $item_url = $item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'sku'}.".html"; print FILE "\n"; } print FILE "
\n"; print FILE "{'title'}\">\n"; #print the item title print FILE "$item->{'title'}\n"; print FILE "
\n"; print FILE "\n"; #For each item, create an html page foreach my $item (@{$rss->{'items'}}) { next unless defined($item->{'title'}) && defined($item->{'link'}); $item_url = $item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'sku'}.".html"; #open item html file open ITEM_FILE, ">".$item_url or die "Cannot Open File: $item_url"; #Write html # Start displaying the HTML result. Use a stylesheet to make it look good, or modify as needed. print ITEM_FILE "$item->{'title'}"; # Print item information print ITEM_FILE "

\n"; #print a link to an item print ITEM_FILE "{'link'}\" title=\"$item->{'title'}\">\n"; #If there is an image, print it if ($item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'imageURL'}) { print ITEM_FILE "{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'imageURL'}\" alt=\"$item->{'title'}\" border=0>  "; } #print the item title print ITEM_FILE "$item->{'title'}\n"; print ITEM_FILE "

\n"; #print the item description print ITEM_FILE "$item->{'description'}
\n"; #print the price and the buy now link print ITEM_FILE "\$$item->{'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'price'}   {'http://www.championshipproductions.com/cgi-bin/champ/rss/'}->{'buynowURL'}\">Buy Now at ChampionshipProductions.com!\n"; print ITEM_FILE "

\n"; print ITEM_FILE "

Back to Main Page

"; print ITEM_FILE "\n"; print ITEM_FILE "\n"; } }