File: cheapo

package info (click to toggle)
libnet-amazon-perl 0.35-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 908 kB
  • ctags: 160
  • sloc: xml: 4,821; perl: 2,055; makefile: 46
file content (65 lines) | stat: -rwxr-xr-x 1,438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
###########################################
# maxauthors keyword
# Mike Schilli <mschilli1@aol.com>, 2003
###########################################

use strict;
use warnings;

use Net::Amazon;
use Net::Amazon::Property;
use Net::Amazon::Request::Keyword;

# use Log::Log4perl qw(:easy);
# Log::Log4perl->easy_init({level => $DEBUG, layout => '%F{1}-%L: %m%n'});

die "usage: $0 keyword" unless 
    defined $ARGV[0];

my $ua = Net::Amazon->new(
    token       => 'YOUR_AMZN_TOKEN',
    max_pages   => 20,
);

my $req = Net::Amazon::Request::Keyword->new(
    keyword   => $ARGV[0],
    mode      => "books"
);

 # Response: Net::Amazon::Keyword::Response
my $resp = $ua->request($req);

if($resp->is_error()) {
    die "Error: ", $resp->message();
}

my $max_authors = 0;
my @books = 
   sort { saved($b) <=> saved($a) }
   grep { $_->Catalog eq "Book" &&
          $_->title =~ /$ARGV[0]/i &&
          $_->ListPrice }
    $resp->properties;

for(0..4) {
    next unless $books[$_];
    printf "%.2f%% (%s/%s) %s\n\n", 
          saved($books[$_]),
          $books[$_]->ListPrice,
          $books[$_]->OurPrice,
          $books[$_]->as_string;
}

###########################################
sub saved {
###########################################
    my($book) = @_;

    my $list = $book->ListPrice;
    my $our  = $book->OurPrice;
    $list =~ s/\$//;
    $our  =~ s/\$//;

    return ($list - $our)/$list*100;
}