続 aws.pl
さすがに悪戦苦闘するのイヤになったのでXML関連のモジュール使わないのを結局、作った。
コンセプトは「ASINサーチが使えればそれで良いや」ですので機能は貧弱貧弱ゥなプラグイン。MTの日本語パッチ(UTF8版)動いてれば動くでしょう。
[code]
# Poor man’s aws.pl
# (C)2004 MDR
# patched MovableType 2.661(Japanse utf-8)
# this plugin doesn’t need XML::* modules.
# ASIN search
# amazon.co.jp
package MT::Plugin::Pmaws;
use MT::Template::Context;
use LWP::Simple;
use Jcode;
my %q;
$q{’dev-t’} = “Your Developer’s token”
$q{’t'} = ‘objblo-22′;
my @pmaws_tags = qw(url ImageUrlSmall ImageUrlMedium ImageUrlLarge ProductName Asin Manufacturer Availability ListPrice OurPrice );
MT::Template::Context->add_container_tag( Pmaws => \&pmaws );
foreach my $tag ( @pmaws_tags ){
MT::Template::Context->add_tag( ‘Pmaws’.$tag => sub { my $ctx = shift; detail($ctx, $tag)});
}
MT::Template::Context->add_tag( PmawsAssociateUrl => \&associateurl );
sub pmaws
{
my $ctx = shift;
my $arg = shift;
my $res = ”;
my $builder = $ctx->stash(’builder’);
my $tokens = $ctx->stash(’tokens’);
my %detail;
$q{keyword} = $arg->{keyword};
$q{mode} = $arg->{mode};
my $url = ‘http://xml.amazon.co.jp/onca/xml3?’;
$url .= sprintf(”t=%s&dev-t=%s&AsinSearch=%s&type=lite&f=xml&locale=jp”,$q{’t'}, $q{’dev-t’}, $q{’keyword’}, $q{’mode’} );
my $xml = LWP::Simple::get($url);
my $f=0;
foreach my $line ( split /\n/, $xml ){
if( $line =~ /
if( $f == 1){
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
if( $line =~ /
}else{;}
if( $line =~ /< \/Details>/ ){$f = 0;}
}
foreach my $tag ( @pmaws_tags ){
$ctx->stash($tag, $detail{$tag});
}
if($q{t}){$ctx->stash(’AssociateUrl’,”http://www.amazon.co.jp/exec/obidos/ASIN/$q{keyword}/$q{t}”)};
defined( my $out = $builder->build( $ctx, $tokens )) or return $ctx->error($ctx->errstr);
$res .= $out;
return $res;
}
sub detail
{
my $ctx = shift;
my $key = shift;
return $ctx->stash($key);
}
sub associateurl
{
my $ctx = shift;
return $ctx->stash(’AssociateUrl’) || ”;
}
1;
[/code]
使い方ー。
$q{dev-t}にDeveloper’s tokenを書き込んで保存。
Pmaws.plとしてpluginディレクトリに入れればOK.
で↓みたいにテンプレートに書く。でRebuild
[code]
< $MTPmawsProductName$>
This entry was posted
on 火曜日, 3月 30th, 2004 at 16時31分01秒 and is filed under Hack?.
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.