#!/usr/bin/perl # Script to turn an Amazon wishlist into an RSS feed. # Pass it a wishlist URL http://www.amazon.co.uk/exec/obidos/registry/3D2QOGRDCFJ70/ref=wl_em_to # Original script from http://sebastian.foriru.co.uk/~sams/ # Copyright (c) 2005 Sam Smith # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use warnings; use strict; use Net::Amazon; use Net::Amazon::Request::Wishlist; use XML::RSS; my ($Url, $Name)=@ARGV; my $Amazon_Token=$ENV{AMAZON_TOKEN} || ''; # Your Amazon WebServices Key { if ($Amazon_Token eq '') {&usage("Edit the script to provide your Amazon WebServices Token\n or provide it in the AMAZON_TOKEN environment variable.")} if (not defined $Url){&usage();} if ($Name) {$Name.="'s"} else {$Name||= 'A'} my ($wishlist, $locale)= &parse_url; &generate_rss(&request_wishlist ($wishlist, $locale)); } sub request_wishlist { my ($wishlist, $locale)= @_; my $ua; if (defined $locale) { #there's surely a cleaner way to do this $ua = Net::Amazon->new( token => $Amazon_Token, locale => $locale ); } else { $ua = Net::Amazon->new( token => $Amazon_Token, ); } my $req=Net::Amazon::Request::Wishlist->new( id => $wishlist); return($ua->request($req)); } sub parse_url { # pull the wishlist ID and locale out of the URL if ($Url=~ m#wishlist#) { # catch a common mistake &usage("You must use the URL as emailed in \"Tell People About Your Wishlist\".\n Not the URL you see when clicking on \"wishlist\"."); } $Url=~ m#(?:http://)?amazon.*?([^\./]+)/.*?/registry/([\w]+)/#; my ($locale, $wishlist)= ($1, $2); unless ($wishlist) {&usage("I can't identify the URL you posted");} if ($locale eq 'com') {$locale=undef}; return($wishlist, $locale); } sub generate_rss { my $response=shift; # type Net::Amazon::ASIN::Response use XML::RSS; my $result; #use Data::Dumper::Simple; #print Dumper($response); my $rss = new XML::RSS (version => '0.91'); $rss->channel( title => "$Name Wishlist", link => "$Url", description => "$Name wishlist.", dc => { subject => "A Wishlist", language => 'en-gb', ttl => 600 }, syn => { updatePeriod => "daily", updateFrequency => "1", updateBase => "1901-01-01T00:00+00:00" }); for $result ($response->properties) { $rss->add_item(title => $result->ProductName, description => " ImageUrlMedium ."\" alt=\" \" /> " .$result->ProductName . ". ". $result->Availability ." at ". $result->OurPrice , link => "$Url#" .$result->Asin # Don't want to bypass the wishlist ); } print $rss->as_string; } sub usage { my $error = shift || ''; if ($error ne '') {$error= "\n$error\n"}; print STDERR <