FrontPage 新規 一覧 検索 ヘルプ ログイン

Amazon Web Service interfaceの変更点

-[動作sample|./asin.cgi]
+*[動作sample|./asin.cgi]
+*[source|./asin_cgi.txt]
-
-
-----
-
- #!/usr/local/bin/perl
- 
- use Jcode;
- use LWP::Simple;
- use Image::Magick;
- 
- my $query = $ENV{'QUERY_STRING'} || "";
- my @query = split(/&/, $query);
- 
- my ($ASIN, $line) = ("", "");
- 
- foreach $line (@query) {
-   if ($line =~ /^ASIN=(.+)$/) {
-     $ASIN = $1;
-   }
- }
- 
- if ($ASIN eq '') {
-   &form;
- } else {
-   &asin($ASIN);
- }
- 
- exit;
- 
- 
- sub form {
- 
-   print "Content-type: text/html; charset=euc-jp\r\n\r\n";
-   print <<"FORM";
- <html>
- <head>
-   <title>Amazon Web Service for TDS</title>
-   <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
- </head>
- <body>
- <h2>Amazon Web Service for TDS</h2>
- 
- <form method=GET action="./asin.cgi">
- ASIN: <input type="text" name="ASIN" size="40" value="">
- <input type=submit value="作成する">
- </form>
- 
- </body>
- </html>
- FORM
- 
-   return 0;
- 
- }
- 
- 
- sub asin($) {
- 
-   my $asin = shift;
-   my ($line, $product, $manu, $imageuri);
-   my @author = ();
-   my @table = ();
- 
-   my $tag = 'webservices-20';
-   my $token = 'D2ED5GR7A6RZ7Y';
-   my $type = 'lite';
-   my $output = 'xml';
-   my $locale = 'jp';
- 
-   my $uri = 'http://xml-jp.amznxslt.com/onca/xml3?';
-   $uri = $uri . 't=' . $tag;
-   $uri = $uri . '&dev-t=' . $token;
-   $uri = $uri . '&type=' . $type;
-   $uri = $uri . '&f=' . $output;
-   $uri = $uri . '&locale=' . $locale;
-   $uri = $uri . '&AsinSearch=' . $asin;
- 
-   my $mode = 'blended';
-   my $encstr = '日本語';
-   $encstr = &uri_encode($encstr);
-   my $search = 'http://www.amazon.co.jp/exec/obidos/external-search?';
-   $search = $search . 'mode=' . $mode;
-   $search = $search . '&tag=' . $tag;
-   $search = $search . '&encoding-string-jp=' . $encstr;
-   $search = $search . '&keyword=';
- 
- 
-   my $content = get("$uri");
-   $content = Jcode->new($content, 'utf8')->euc;
-   my @content = split(/\n/, $content);
- 
-   foreach $line (@content) {
-     if ($line =~ /<ProductName>(.*)<\/ProductName>/) {
-       $product = $1;
-     } elsif ($line =~ /<Author>(.*)<\/Author>/) {
-       push(@author, $1);
-     } elsif ($line =~ /<Artist>(.*)<\/Artist>/) {
-       push(@author, $1);
-     } elsif ($line =~ /<Manufacturer>(.*)<\/Manufacturer>/) {
-       $manu = $1;
-     } elsif ($line =~ /<ImageUrlMedium>(.*)<\/ImageUrlMedium>/) {
-       $imageuri = $1;
-     }
-   }
- 
-   my $imagetmp = '/tmp/image.tmp';
-   my $wgetarg = "-q -t 3 -O $imagetmp";
-   system("/usr/local/bin/wget $wgetarg '$imageuri'");
- 
-   my $image = new Image::Magick;
-   $image->Read("$imagetmp");
-   my ($width, $height) = $image->Get('columns', 'height');
-   if (($width == 1) & ($height == 1)) {
-     $imageuri = "http://images-jp.amazon.com/images/G/09/x-locale/detail/thumb-no-image.gif";
-     $width = 50;
-     $height = 60;
-   }
- 
-   push(@table, "<table border=\"1\">\n");
-   push(@table, "<tr>\n");
-   push(@table, "<td align=\"center\" rowspan=\"3\">\n");
-   push(@table, "<a href=\"http://www.amazon.co.jp/exec/obidos/ASIN/$asin/$tag\">\n");
-   push(@table, "<img src=\"$imageuri\"");
-   push(@table, " height=\"$height\" width=\"$width\"");
-   push(@table, " vspace=\"3\" hspace=\"5\" border=\"0\" alt=\"amazon\">\n");
-   push(@table, "</a>\n");
-   push(@table, "</td>\n");
-   push(@table, "<td>\n");
-   push(@table, "<a href=\"http://www.amazon.co.jp/exec/obidos/ASIN/$asin/$tag\">\n");
-   push(@table, "$product\n");
-   push(@table, "</a>\n");
-   push(@table, "</td>\n");
-   push(@table, "</tr>\n");
-   push(@table, "<tr>\n");
-   push(@table, "<td>\n");
-   if ($#author eq "-1") {
-     push(@table, "<br>\n");
-   } else {
-     foreach $line (@author) {
-       my $encauth = &uri_encode($line);
-       my $searchuri = $search . $encauth;
-       push(@table, "<a href=\"$searchuri\">$line</a><br>\n");
-     }
-   }
-   push(@table, "</td>\n");
-   push(@table, "</tr>\n");
-   push(@table, "<tr>\n");
-   push(@table, "<td>\n");
-   if ($manu eq "") {
-     push(@table, "<br>\n");
-   } else {
-     my $encmanu = &uri_encode($manu);
-     $searchuri = $search . $encmanu;
-     push(@table, "<a href=\"$searchuri\">$manu</a><br>\n");
-   }
-   push(@table, "</td>\n");
-   push(@table, "</tr>\n");
-   push(@table, "</table>\n");
- 
- 
-   print "Content-type: text/html\r\n\r\n";
-   print <<"ASIN1";
- <html>
- <head>
-   <title>Amazon Web Service for TDS</title>
-   <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
- </head>
- <body>
- <h2>Amazon Web Service for TDS</h2>
- 
- <form method=GET action="./asin.cgi">
- ASIN1
- 
-   print 'ASIN: <input type="text" name="ASIN" size="40" value="';
-   print "$asin\">\n";
- 
-   print <<"ASIN2";
- <input type=submit value="作成する">
- </form>
- <hr>
- ASIN2
- 
-   print "@table";
-   print "<hr>\n";
-   print "<form action=\"/dev/null\">\n";
-   print "<textarea name=\"TABLE\" wrap=\"off\" cols=80 rows=20>";
-   print "VERBATIM\n";
-   print "@table";
-   print "/VERBATIM\n";
-   print "</textarea>\n";
-   print "</form>\n";
- 
-   print "<hr>\n";
-   print "<form action=\"/dev/null\">\n";
-   print "<textarea name=\"XML\" wrap=\"off\" cols=80 rows=20>";
-   print "$content\n";
-   print "</textarea>\n";
-   print "</form>\n";
- 
-   print "</body>\n</html>\n";
- 
-   return 0;
- 
- }
- 
- 
- sub uri_encode($) {
-   my $str = shift;
-   $str =~ s/([^\w])/'%'.unpack('H2', $1)/eg;
- #  $str =~ s/([^\w ])/'%'.unpack('H2', $1)/eg;
- #  $str =~ tr/ /+/;
-   return $str;
- }
- 
- sub uri_decode($) {
-   my $str = shift;
-   $str =~ tr/+/ /;
-   $str =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg;
-   return $str;
- }