--- /home/caio1982/.cpan/sources/authors/id/M/MT/MTHURN/WWW-Amazon-Wishlist-2.006/Programs/amazonwish 2009-08-26 19:03:50.000000000 -0300 +++ /usr/local/bin/amazonwish 2009-10-23 18:00:17.000000000 -0200 @@ -1,6 +1,5 @@ -#!perl -w -- -*- cperl -*- -#line 2 -# +#!/usr/bin/perl -w -- -*- cperl -*- + # Grab all the values from your Amazon Wish list # and then print it out - surprisingly scary (at # least in my case, it came out over a grand) @@ -25,7 +24,7 @@ use strict; use LWP::UserAgent; use Getopt::Long; -use WWW::Amazon::Wishlist qw(get_list COM UK); +use WWW::Amazon::Wishlist qw(get_list COM UK DE FR CA); our $VERSION = do { my @r = (q$Revision: 2.6 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; @@ -38,6 +37,9 @@ # set up some variables my $uk = 0; +my $ca = 0; +my $de = 0; +my $fr = 0; my $suffix = 'com'; my $match = '\$'; my $symbol = '$'; @@ -50,6 +52,9 @@ my $opt_version; die unless GetOptions( 'uk' => \$uk, + 'ca' => \$ca, + 'de' => \$de, + 'fr' => \$fr, 'id=s' => \$id, 'force' => \$force, 'save' => \$save, @@ -67,8 +72,11 @@ my $name; ($name = $0) =~ s!^.*[\\/]!!; print STDOUT << "ENDOFHELP"; -% $name [-uk] [-id ID] [-force] [-save] [-verbose] [-help] --uk : get values from amazon.co.uk (default is .com) +% $name [-uk|-ca|-de|-fr] [-id ID] [-force] [-save] [-verbose] [-help] +-uk : get values from amazon.co.uk +-ca : get values from amazon.ca +-de : get values from amazon.de +-fr : get values from amazon.fr -id : your amazon wish list id (it's the last bit of the URL after /wishlist/) -force : don't look up values from the resource file -save : save these values to the resource files @@ -147,12 +155,23 @@ die "You haven't defined an id\n" unless (defined $id); # if it's a uk version update the variables -if ($uk) - { - $suffix = "co.uk"; +if ($uk) { $match = "£"; $symbol = "£"; - } # if + $suffix = "uk"; +} elsif ($ca) { + $match = "$"; + $symbol = "C\$"; + $suffix = "ca"; +} elsif ($de || $fr) { + $match = "€"; + $symbol = "¿"; + if ($de) { + $suffix = "de"; + } elsif ($fr) { + $suffix = "fr"; + } +} # if # and write out to our resource file unless (-e $res && !$save) @@ -163,10 +182,18 @@ } # unless my $iBooks = 0; -foreach my $bookref (get_list ($id, $uk)) +foreach my $bookref (get_list ($id, $uk, $ca, $de, $fr)) { my %book = %{$bookref}; - $book{'price'} =~ s/[^.\d]//g; + + # We should find a nicer way to handle Euro + if ($de || $fr) { + $book{'price'} =~ s/[^,\d]//g; + $book{'price'} =~ s/,/./g; + } else { + $book{'price'} =~ s/[^.\d]//g; + } + $book{price} = 0 if ($book{price} eq q{}); if ($verbose) { @@ -202,6 +229,12 @@ -uk : get values from amazon.co.uk (default is .com) +-ca : get values from amazon.ca + +-de : get values from amazon.de + +-fr : get values from amazon.fr + -id : your amazon wish list id (it's the last bit of the URL after /wishlist/) -force : don't look up values from the resource file --- /home/caio1982/.cpan/sources/authors/id/M/MT/MTHURN/WWW-Amazon-Wishlist-2.006/lib/WWW/Amazon/Wishlist.pm 2009-08-26 19:04:49.000000000 -0300 +++ /usr/lib/perl5/site_perl/5.10.0/WWW/Amazon/Wishlist.pm 2009-10-23 18:01:36.000000000 -0200 @@ -13,6 +13,9 @@ use constant COM => 0; use constant UK => 1; +use constant CA => 2; +use constant DE => 3; +use constant FR => 4; use constant DEBUG => 0; use constant DEBUG_HTML => 0; @@ -29,6 +32,9 @@ @EXPORT_OK = qw( get_list UK + CA + DE + FR COM ); @@ -69,7 +75,7 @@ =head1 DESCRIPTION -Goes to amazon.(com|co.uk), scrapes your wishlist, and returns it +Goes to amazon.(com|co.uk|.de|.ca|.fr), scrapes your wishlist, and returns it in a array of hashrefs so that you can fiddle with it to your heart's content. @@ -90,7 +96,7 @@ bit that's important. -Doing the same for amazon.co.uk is just as easy. +Doing the same for amazon.co.uk or any other Amazon domain is just as easy. Apparently, some people have had problems getting to their wishlist right after it gets set up. You may have to wait a while for it to become @@ -151,7 +157,7 @@ sub get_list { - my ($id, $uk, $test) = @_; + my ($id, $uk, $ca, $de, $fr, $test) = @_; if (! defined $id) { croak "No ID given to get_list function\n"; @@ -160,9 +166,24 @@ # note to self ... should we UC the id? Nahhhh. Not yet. # Default is amazon.com: $uk |= 0; + $ca |= 0; + $fr |= 0; + $de |= 0; $test |= 0; + # fairly self explanatory - my $domain = ($uk)? "co.uk" : "com"; + my $domain = "com"; + + if ($uk) { + $domain = "co.uk"; + } elsif ($de) { + $domain = "de"; + } elsif ($fr) { + $domain = "fr"; + } elsif ($ca) { + $domain = "ca"; + } + # set up some variables my $iPage = 1; my @items; @@ -170,8 +191,7 @@ INFINITE: while (1) { - my $url = $uk ? "http://www.amazon.co.uk/gp/registry/wishlist/$id/?page=$iPage" : - "http://www.amazon.com/gp/registry/wishlist/$id/?page=$iPage"; + my $url = "http://www.amazon.$domain/gp/registry/wishlist/$id/?page=$iPage"; # This is a typical complete .com URL as of 2008-12: # http://www.amazon.com/gp/registry/wishlist/2O4B95NPM1W3L DEBUG_HTML && print STDERR " DDD fetching wishlist for $id, page $iPage...\n"; @@ -193,7 +213,20 @@ # print STDERR " DDD fetched $iLen bytes.\n"; return undef unless ($content); # print STDERR " DDD call _extract()\n"; - my $result = _extract($uk, $content); + + my $store; + if ($uk) { + $store = $uk; + } elsif ($ca) { + $store = $ca; + } elsif ($de) { + $store = $de; + } elsif ($fr) { + $store = $fr; + } + + my $result = _extract($store, $content); + # print Dumper($result); # exit 88; last INFINITE if (! defined $result); @@ -226,7 +259,16 @@ # DEBUG && print STDERR " DDD content===$content===\n"; # exit 88; # Use brute force to find it: - if ($content =~ m!(&(amp;)?page=\d+)">\s*(<[^>]+>)?Next!) + my $next = "Next"; + + # Handling the Euro zone + if ($de) { + $next = "Weiter"; + } elsif ($fr) { + $next = "Suivant"; + } + + if ($content =~ m!(&(amp;)?page=\d+)">\s*(<[^>]+>)?$next!) { DEBUG && print STDERR " DDD found next URL with brute force\n"; $sURLNext = $1; @@ -329,6 +371,9 @@ { # Required arg1 = whether we are parsing the UK site or not (Boolean): my $iUK = shift || 0; + my $iCA; + my $iDE; + my $iFR; # Required arg2 = the HTML contents of the webpage: my $s = shift || ''; DEBUG_HTML && print STDERR " DDD start _extract()\n"; @@ -336,12 +381,14 @@ my $oTree = new HTML::TreeBuilder; $oTree->parse($s); $oTree->eof; - my @aoSPAN = $iUK ? $oTree->look_down(_tag => 'td', - class => 'small', - ) - : $oTree->look_down(_tag => 'span', - class => 'small productTitle', - ); + + my @aoSPAN; + if ($iUK || $iCA || $iDE || $iFR) { + @aoSPAN = $oTree->look_down(_tag => 'td', class => 'small', ); + } else { + @aoSPAN = $oTree->look_down(_tag => 'span', class => 'small productTitle', ); + } + SPAN_TAG: foreach my $oSPAN (@aoSPAN) { @@ -454,7 +501,7 @@ # Find the "author" of this item: my @aoTD; - if ($iUK) + if ($iUK || $iCA || $iDE || $iFR) { @aoTD = $oParent->look_down(_tag => 'td', class => 'small',