// ==UserScript==
// @name broken source
// @namespace xxxxxx
// @description broken source
// @include http://*
// ==/UserScript==
})();
(function () {
これOKでつか...イケるんですか...
// ==UserScript==
// @name broken source
// @namespace xxxxxx
// @description broken source
// @include http://*
// ==/UserScript==
})();
(function () {
これOKでつか...
AWSWORD:ほにゃらら:
※「ほにゃらら」は英数字もしくは「_」
ASIN:4844322893
と書けば
AWSWORD:perl:
と書けば
--- awsxom.orig Thu Nov 30 22:12:17 2006
+++ awsxom Tue Mar 18 09:32:22 2008
@@ -57,17 +57,20 @@
# ASIN/ISBNが書かれていたら置き換える
# テンプレート指定版
- s/(?:ASIN|ISBN):([A-Z0-9]{10}):(.*?):/to_html($1,$2)/ge;
+ s/(?:ASIN|ISBN):([A-Z0-9]{10}):(.*?):/to_html_asin($1,$2)/ge;
# テンプレート無指定版
- s/(?:ASIN|ISBN):([A-Z0-9]{10})/to_html($1,$default_template)/ge;
+ s/(?:ASIN|ISBN):([A-Z0-9]{10})/to_html_asin($1,$default_template)/ge;
+
+ # テンプレート無指定版
+ s/(?:AWSWORD):([a-zA-Z0-9_]*?):/to_html_word($1,$default_template)/ge;
return $_;
}
# ---------------------------------------------------------------------
# ASINからAmazonのアフィリエイト用HTMLを作成
-sub to_html {
+sub to_html_asin {
my ($asin, $template) = @_; # ASINとテンプレ名称
my $cache = "$cachedir/$asin.xml";
my $url = "http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService&SubscriptionId=$devkey&AssociateTag=$asoid&Operation=ItemLookup&ItemId=$asin&ResponseGroup=Medium,Offers";
@@ -90,8 +93,57 @@
# テンプレートを展開。エラーの場合はエラー文字列を返す
my $form;
if (!defined($detail{"ErrorMsg"})) {
- $form = &$blosxom::template($blosxom::path, $template, 'html');
- $form =~ s/\$(\w+)/$detail{$1}/ge;
+ #$form = &$blosxom::template($blosxom::path, $template, 'html');
+ my $fh = new FileHandle;
+ if ($fh->open("< $blosxom::datadir/$template.html")) {
+ $form = join '', <$fh>;
+ $form =~ s/\$(\w+)/$detail{$1}/ge;
+ $fh->close();
+ }
+ }
+ else {
+ $form = "<p>" . $detail{"ErrorMsg"} . "</p>";
+ }
+
+ return $form;
+}
+
+# ---------------------------------------------------------------------
+# ASINからAmazonのアフィリエイト用HTMLを作成
+sub to_html_word {
+ my ($word, $template) = @_; # ASINとテンプレ名称
+ my $cache = "$cachedir/$word.xml";
+ my $url = "http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService&SubscriptionId=$devkey&AssociateTag=$asoid&Operation=ItemSearch&Keywords=$word&SearchIndex=Books&ResponseGroup=Medium,Offers";
+ my $outfile = "$cachedir/$word.html";
+
+ # 取り込み直す必要はあるか?
+ if (!(-e $cache) || (-M $cache > ($EXPIRE / 24))) {
+ # AWSから情報を取得してキャッシュファイルに保存
+ # UserAgent初期化
+ my $ua = new LWP::UserAgent;
+ $ua->agent($ua_name);
+ $ua->timeout(60);
+ my $rtn = $ua->mirror($url, $cache);
+ }
+
+ # キャッシュからXMLを読み込んで解析
+ my $content = getFile($cache);
+ $content =~ s!.*?(<Item>.*?</Item>).*!$1!is;
+ my $asin = "";
+ $asin = $1 if ($content =~ /<ASIN>([^<]*)<\/ASIN>/);
+ return "" if !$asin;
+ my %detail = parseXML($content, $asin);
+
+ # テンプレートを展開。エラーの場合はエラー文字列を返す
+ my $form;
+ if (!defined($detail{"ErrorMsg"})) {
+ #$form = &$blosxom::template($blosxom::path, $template, 'html');
+ my $fh = new FileHandle;
+ if ($fh->open("< $blosxom::datadir/$template.html")) {
+ $form = join '', <$fh>;
+ $form =~ s/\$(\w+)/$detail{$1}/ge;
+ $fh->close();
+ }
}
else {
$form = "<p>" . $detail{"ErrorMsg"} . "</p>";
ちなみに、先日図書館で見つけた本で面白いの見つけた。
" DO NOT EDIT
scriptencoding utf-8
let s:self = expand("<sfile>")
com! UseDataToken exe join(map(remove(readfile(s:self),5,8),"strpart(v:val,1)"),"|")
"__DATA__
"silent! unlet datatoken
"let datatoken=readfile(expand("<sfile>"))
"cal remove(datatoken,0,search("^\"__DATA__$")-1)
"cal map(datatoken,"strpart(v:val,1)")
こんな感じで使う側はこんな感じ
"source datatoken.vim
UseDataToken
silent! unlet d
let d = eval(join(datatoken))
echo d.author
echo d.version
echo d.date
"__DATA__
"{
"'author': 'mattn <mattn.jp@gmail.com>',
"'version': '0.001',
"'date': 'Mon, 17 Mar 2008'
"}
perlの様にファイルハンドルでないのが気持ち悪いか。このブログを応援する