#!/usr/bin/perl use LWP::Simple; use XML::RSS; use strict; # the actual value of this variable should be the URI for your RSS # file as given on the developer home page ("etc" should be # your unique ID string) # NOTE: if you're using a locally cached version, change this URI # to point to the location of the local file (e.g., /var/tmp/rss/ratings.rss) my $rssfile = "http://www.macupdate.com/rss/ratings.rss?id=etc"; my $PROGRAM_TO_DISPLAY = "Your Program Name"; ## utility subroutines sub write_item { my $item = shift; my $rating = $item->{'description'}; my $formattedRating = sprintf("%.1f", $rating); # display rating with 1 decimal pt my $starsRating = round($rating * 2) / 2; # calculated nearest-half rating my $stars = ($starsRating >= 1) ? "http://www.macupdate.com/images/stars${starsRating}.gif" : "http://www.macupdate.com/images/stars0.gif"; my $link = $item->{'link'}; # link to info page on macupdate.com my $resultString = "
\n"; $resultString .= "
$starsRating stars ($formattedRating)
\n"; $resultString .= "
MacUpdate
\n"; $resultString .= "($item->{'title'})
\n\n"; return $resultString; } sub itemsForTitle { our $rss; my $title = shift; return grep { $_->{'title'} eq $title } @{$rss->{'items'}}; } # instantiate a new parser, and get the contents of your RSS file my $rss = new XML::RSS (version => '2.0'); my $data = get($rssfile); # parse the RSS file data $rss->parse($data); print < RSS Parsing Example (Perl) EOT # write info for the first item (note the print statement!) matching name my @itemList = itemsForTitle($PROGRAM_TO_DISPLAY); print write_item(shift @itemList); # write info for each item foreach my $item (@{$rss->{'items'}}) { print write_item($item); } # write info for each item w/rating > 3 foreach my $item (@{$rss->{'items'}}) { if ($item->{'description'} > 3) { print write_item($item); } } print < EOT