EDGE Now!の覆面の中の人暴露
スポンサードリンク
Edge Now!は、サーバからXMLを取得していろいろランキングとか出しているんですけれども、せっかくなんで、SBMのブックマーク件数とのマッシュアップ(笑)をしてみました。
いつものごとくソースおいときますね。
Filename: bloggersranking.cgi
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use HTML::Template;
use LWP::Simple;
use utf8;
use XML::Simple;
binmode STDOUT => ':utf8';
my $xml_url = 'http://edgenow.jp/xml/bloggerThis.php';
my $masklist =
[
{
image => '00832mask.png',
rank => 'AAA',
order => 1,
message => '組織の最上部で皆の安全を見守るのがトップである'
.'自分の仕事なのに今じゃAAが自分の下で組織をを'
.'見守っているじゃないか',
},
{
image => '01635mask.png',
rank => 'AA',
order => 2,
message => 'このかぶりモンやとさすがに戦えへんわ',
},
{
image => '02765mask.png',
rank => 'A',
order => 3,
message => 'まわりが触れないぐらいの穴なら問題なく通れます',
},
{
image => '03657mask.png',
rank => 'B',
order => 4,
message => 'つので大豆がつまめます 大豆以外もつまめます',
},
{
image => '04961mask.png',
rank => 'C',
order => 5,
message => '俺戦隊系というよりライダー系だよね',
},
{
image => '05038mask.png',
rank => 'D',
order => 6,
message => 'サイバトロンちゃうわ',
},
{
image => '06092mask.png',
rank => 'E',
order => 7,
message => 'カタヌキでオレがでたら諦めてくれ',
},
{
image => '07811mask.png',
rank => 'F',
order => 8,
message => 'このマスクつけていると戦わずに済むわい',
},
{
image => '08036mask.png',
rank => 'G',
order => 9,
message => 'サ○エでございます',
},
{
image => '09173mask.png',
rank => 'H',
order => 10,
message => 'クチまるみえなんだけど?ライダーマンいやだわー',
},
{
image => '10346mask.png',
rank => 'I',
order => 11,
message => 'リーダーやねんけどうちの組織上いっぱいおるんよ',
},
{
image => '11803mask.png',
rank => 'J',
order => 12,
message => '青は4人居るねんて',
},
{
image => '11803mask.png',
rank => 'J',
order => 13,
message => 'しゃーないなー',
},
{
image => '11803mask.png',
rank => 'J',
order => 14,
message => 'ほな麻雀でも',
},
{
image => '11803mask.png',
rank => 'J',
order => 15,
message => 'あかん金無いわ',
},
{
image => '12384mask.png',
rank => 'K',
order => 16,
message => 'まりもっこりいうなー',
},
{
image => '13124mask.png',
rank => 'L',
order => 17,
message => 'またアクタースーツの胸のあたりがきつくなってきたー',
},
{
image => '14567mask.png',
rank => 'M',
order => 18,
message => '粉のままでいいからくれ!はーやーくー',
},
{
image => '15944mask.png',
rank => 'N',
order => 19,
},
{
image => '16534mask.png',
rank => 'O',
order => 101,
},
{
image => '17081mask.png',
rank => 'P',
order => 151,
},
{
image => '18616mask.png',
rank => 'Q',
order => 201,
},
{
image => '19018mask.png',
rank => 'R',
order => 251,
message => 'このまえ戦闘員と間違われて死にかけたw',
},
];
my $tmpl_html = <<'END_OF_HTML';
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
<title>EDGE Now!の覆面の中の人暴露</title>
<meta http-equiv="content-script-type"
content="text/javascript" />
<meta http-equiv="content-style-type"
content="text/css" />
<link rel="index" href="./" />
<link rev="made" href="mailto:aab61120@pop12.odn.ne.jp" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="RSS"
href="http://labo.dtpwiki.jp/edgenow/index.rdf" />
<link rel="stylesheet" href="default.css" type="text/css" />
<style>
body {
text-align: center;
}
div#contents {
width: 700px;
margin: 0px auto;
text-align: left;
}
table {
border-collapse: collapse;
}
thead th {
background-color: #333;
color: white;
}
tbody th {
background-color: white;
}
tbody .even th,
tbody .even td {
background-color: #d0d0d0;
}
.posted em {
background-color: #fff0f0;
font-weight: bold;
font-style: normal;
}
.posted em a,
.posted em a:link,
.posted em a:visited,
.posted em a:hover,
.posted em a:active {
color: #f66;
font-weight: bold;
font-style: normal;
}
.posted strong {
background-color: #fcc;
font-weight: bold;
font-style: normal;
display: inline;
}
.posted strong a,
.posted strong a:link,
.posted strong a:visited,
.posted strong a:hover,
.posted strong a:active {
color: red;
font-weight: bold;
font-style: normal;
text-decoration: none;
}
.posted a,
.posted a:link,
.posted a:visited,
.posted a:hover,
.posted a:active {
text-decoration: none;
color: blue;
}
</style>
</script>
</head>
<body>
<div id="contents">
<h1>EDGE Now!の覆面の中の人暴露</h1>
<p>
Adobe EDGE Now!のブロガーランキングで表示される
覆面の中の人のサイトの実際の人気を暴きます。
</p>
<p>
<a href="http://edgenow.jp/" target="_blank">EDGE Now!</a>
</p>
<table border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>
RANK
</th>
<th>
MASK
</th>
<th style="width: 300px;">
Message
</th>
<th style="width: 90px;">
中の人の名前
</th>
<th style="width: 80px;">
実際の人気
</th>
</tr>
</thead>
<tbody>
<tmpl_loop name="loop_masks">
<tr<tmpl_unless name="__odd__"> class="even"</tmpl_unless>>
<th>
<tmpl_var name="rank" escape="html">
</th>
<td>
<img src="images/<tmpl_var name="image" escape="url">">
</td>
<td>
<tmpl_var name="message" escape="html">
</td>
<td style="text-align: center;">
<a href="<tmpl_var name="url">" target="_blank">
<img src="http://edgenow.jp/member/pic/<tmpl_var name="id">.gif"
width="50" height="50" border="0" /><br />
<tmpl_var name="name" escape="html"></a>
</td>
<td class="posted">
<script type="text/javascript" charset="UTF-8"
src="http://labo.dtpwiki.jp/sbm/check.cgi?url=<tmpl_var
name="url">&mode=js"></script>
</td>
</tr>
</tmpl_loop>
</tbody>
<table>
</div>
</body>
</html>
END_OF_HTML
my $xs = XML::Simple->new();
my $ref = $xs->XMLin( get( $xml_url ), forcearray => 1 );
my $showlist;
foreach my $item ( @{$ref->{bloggerListThis}->[0]->{blogger} } ) {
my $temp_item = shift @$masklist;
$temp_item = { %$temp_item,
id => $item->{id },
url => $item->{url }->[0],
title => $item->{title}->[0],
name => $item->{name }->[0],
};
push @$showlist, $temp_item;
}
my $tmpl = HTML::Template->new(
scalarref => \$tmpl_html,
die_on_bad_params => 0,
loop_context_vars => 1,
);
$tmpl->param( 'loop_masks' => $showlist, );
my $q = CGI->new();
print $q->header( -type => 'text/html', -charset => 'UTF-8',);
print $tmpl->output();
exit;
__END__
今回のポイントは、XML::Simpleのforcearray => 1です。吐き出されるXMLのリスト、ランク順に出てきて、つまり順序に依存しているんです。だから、forcearray => 1がついていないハッシュのままだと、ランク順に取得できないのでした。
XMLで出現順序に依存(XML用語でなんていうか知らんが)ていうの結構多いので注意しよう。
スポンサードリンク
トラックバック(0)
トラックバックURL: http://blog.dtpwiki.jp/MTOS/mt-tb.cgi/2422






![: Amazon.co.jp: プラスティック・メモリーズ 1【完全生産限定版】(イベントチケット優先販売申込券付) [Blu-ray]](/lists/_9/B00VWX66E8.jpg)
![: Amazon.co.jp: プラスティック・メモリーズ 2【完全生産限定版】[Blu-ray]](/lists/_9/B00VWX66K2.jpg)
![: Amazon.co.jp: プラスティック・メモリーズ 3【完全生産限定版】[Blu-ray]](/lists/_9/B00VWX6MV0.jpg)
![: Amazon.co.jp: プラスティック・メモリーズ 4【完全生産限定版】[Blu-ray]](/lists/_9/B00VWX66IO.jpg)
![: Amazon.co.jp: プラスティック・メモリーズ 5【完全生産限定版】[Blu-ray]](/lists/_9/B00VWX6Y0E.jpg)
![: Amazon.co.jp: プラスティック・メモリーズ 6【完全生産限定版】[Blu-ray]](/lists/_9/B00VWX69D6.jpg)


コメントする