炊飯器で豆腐ハンバーグ
たまたまテレビで見たのでメモ。近いうちに作る。きっと。
手順
Last.fm API の結果を HTML::Template を使って出力する
Last.fmのAPIと「XML::Simple」 - ragutarouの日記の発展形。
Last.fm APIを使い、"ragtime"タグが多く付けられているアーティストを抜き出す。その結果(xml)を HTML::Template を使ってcgiで表示させる。
#!/usr/bin/perl -T use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use LWP::Simple; use XML::Simple; use HTML::Template; my $tag = "ragtime"; my $url = "http://ws.audioscrobbler.com/1.0/tag/$tag/topartists.xml"; my $ls = LWP::Simple::get($url) or die $!; my $xs = XML::Simple->new; my $ref = $xs->XMLin($ls); my @data; for (keys %{$ref->{artist}}) { push @data, { ARTIST => $_, URL => $ref->{artist}->{$_}->{url}, COUNT => $ref->{artist}->{$_}->{count} }; } # Countで降順ソート my @sorted = sort { $b->{COUNT} <=> $a->{COUNT} } @data; ##__PRINT_HTML__ # header my $q = new CGI; print $q->header(-charset => 'utf-8'), $q->start_html('HTML::Template Test'); # template - loop my $tp = HTML::Template->new(filename => 'lastfm.tmpl'); $tp->param(ARTIST_INFO => \@sorted); print $tp->output;
■テンプレートファイル (lastfm.tmpl)
<table border=1> <TMPL_LOOP NAME=ARTIST_INFO> <tr> <td><TMPL_VAR NAME=ARTIST></td> <td><TMPL_VAR NAME=URL></td> <td><TMPL_VAR NAME=COUNT></td> </tr> </TMPL_LOOP> </table>
■出力結果
<title>HTML::Template Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <table border=1> <tr> <td>Scott Joplin</td> <td>http://www.last.fm/music/Scott+Joplin</td> <td>79</td> </tr> <tr> <td>The Ditty Bops</td> <td>http://www.last.fm/music/The+Ditty+Bops</td> <td>11</td> </tr> <tr> <td>Jelly Roll Morton</td> <td>http://www.last.fm/music/Jelly+Roll+Morton</td> <td>9</td> </tr> 〜以下、省略〜
ローカルのWebサーバで確認したところ、外部のAPIに問合せているとはいえ画面が表示されるまで4秒程度…おっそ!
"bind-9.4.1-P1"にてclients-per-queryメッセージ
syslogにnamedプロセスからのdaemon.noticeメッセージが大量に出ていたので調べてみました。
Jan 28 14:09:27 host-name named[9965]: [ID 873579 daemon.notice] clients-per-query decreased to 12
Jan 28 14:29:27 host-name named[9965]: [ID 873579 daemon.notice] clients-per-query decreased to 11
Jan 28 14:49:27 host-name named[9965]: [ID 873579 daemon.notice] clients-per-query decreased to 10
Jan 28 15:56:31 host-name named[9965]: [ID 873579 daemon.notice] clients-per-query increased to 11
環境
- OS : Solaris 8
- Bind : 9.4.1-P1
解決方法
http://mlog.euqset.org/archives/installer/1353.htmlのサイトによると以下の情報がありました。
2260. [bug] Reported wrong clients-per-query when increasing the value. [RT #17236]
結論としては、BIND 9.5.0b1にアップデートすることでこのバグが回避されるようです。
Last.fmのAPIと「XML::Simple」
やりたいこと
Last.fmのAPI(http://www.audioscrobbler.net/data/webservices/)と XML::Simple モジュールを使って、"ragtime"というタグ名からTopArtist(人気のあるアーティスト)を抜き出す。
#!/usr/local/bin/perl use strict; use warnings; use LWP::Simple; use XML::Simple; my $tag = "ragtime"; my $url = "http://ws.audioscrobbler.com/1.0/tag/$tag/topartists.xml"; my $ls = LWP::Simple::get($url) or die $!; my $xs = XML::Simple->new; my $ref = $xs->XMLin($ls); # ハッシュから、"アーティスト名", "Count(タグをつけたユーザ数)", "URL" を表示 for (keys %{$ref->{artist}}) { warn "Artist => $_\n", "URL => $ref->{artist}->{$_}->{url}\n", "Count => $ref->{artist}->{$_}->{count}\n\n"; }
XMLの出力 (http://ws.audioscrobbler.com/1.0/tag/ragtime/topartists.xml)
−<tag tag="ragtime" count="686"> −<artist name="Scott Joplin" count="79" streamable="yes"> <mbid>aec8a328-d2e8-4780-b2ea-318c7f8d6f75</mbid> <url>http://www.last.fm/music/Scott+Joplin</url> <thumbnail>http://userserve-ak.last.fm/serve/50/412356.jpg</thumbnail> <image>http://userserve-ak.last.fm/serve/160/412356.jpg</image> </artist> −<artist name="The Ditty Bops" count="11" streamable="yes"> <mbid>822c67fc-ab63-42ad-b27a-66039e37fe00</mbid> <url>http://www.last.fm/music/The+Ditty+Bops</url> <thumbnail>http://userserve-ak.last.fm/serve/50/63625.jpg</thumbnail> <image>http://userserve-ak.last.fm/serve/160/63625.jpg</image> </artist> -〜以下、省略〜
$ref のDump出力
artist:
Winifred Atwell:
count: 2
image: http://userserve-ak.last.fm/serve/160/103319.jpg
mbid: b182700d-c0e2-4e3a-8373-e57a76333227
streamable: yes
thumbnail: http://userserve-ak.last.fm/serve/50/103319.jpg
url: http://www.last.fm/music/Winifred+Atwell
Zez Confrey:
count: 2
image: http://cdn.last.fm/depth/catalogue/noimage/noartist_140px.jpg
mbid: 29fa57fe-26de-4249-9e85-5d41f760b252
streamable: yes
thumbnail: http://cdn.last.fm/depth/catalogue/noimage/noartist_50px.jpg
url: http://www.last.fm/music/Zez+Confrey
〜以下、省略〜
count: 686
tag: ragtime
スクリプトの出力結果
Artist => William Albright
URL => http://www.last.fm/music/William+Albright
Count => 4
Artist => Bowman, Euday L.
URL => http://www.last.fm/music/Bowman%2C+Euday+L.
Count => 1
〜以下、省略〜
もっとやりたいこと
- CountでソートしてTop10表示とか
- XML::Simple は遅いらしいので、違うモジュールも試してみたい
さくらインターネットにて vim, screen, zsh のインストール
さくらインターネットのレンタルサーバでは vim, screen, zsh が入っていないため、インストールをしました。
Vim のインストール (Ver 7.1)
- さくらインターネットの共用サーバに vim をインストールする - talk to oneself 2を参考に・・
- ~/.vimrc ファイルを作成
screen のインストール (Ver 4.0.3)
- さくらインターネットにemacs,zsh,screenをインストールする - wasabi0522's blogを参考に・・
- ~/local/screen/bin にパスを通す
- ~/.screenrc ファイルを作成
- ※設定は再ログイン後に反映
zsh のインストール (Ver 4.2.7)
※ 最新バージョン4.3.4(http://www.zsh.org/pub/zsh-4.3.4.tar.bz2)をインストールしようとしたのですが、makeに失敗したので、4.2.7を入れました。
- さくらインターネットにemacs,zsh,screenをインストールする - wasabi0522's blogを参考に・・
- ~/.zshrc ファイルを作成
- ログイン時にzshを起動させるため、~/.login ファイルに以下の行を追加
その他、細かな設定
ls のカラー表示
- ~/.zshrc に以下を追加
alias ll='ls -lG' alias ls='ls -G'
screenの設定 (~/.screenrc)
## ビジュアルベルを無効 vbell off ## ステータス行の設定 hardstatus alwayslastline "[%02c] %`%-w%{=b bw}%n %t%{-}%+w" ## スタートアップ時メッセージ無効 startup_message off ## 自動でデタッチする autodetach on ## 文字コードにUTF-8を使う defutf8 on ## スクロール行を 10,240行 defscrollback 10240 ## (C-a k)でウィンドウを閉じる bind ^k kill
この中で自分的に重要なのが「ステータス行の設定」かな。エスケープキャラクタ(C-a)の変更はしていません。
id:naoya さんが書かれた『WEB+DB PRESS vol.40』を参考にしています。僕はこれを定期購読しており、技術系雑誌の中では一番のお気に入りです。
携帯のフィルタリングソフト
■子供に尾崎を聴かせると盗んだバイクで走り出してしまうからダメ
http://neta.ywcafe.net/000824.html
タイトルでついクリックしてしまった31の夜。
「モバゲーダウン」という10〜20代の若い世代に人気の携帯サイトがあります。このサイトが未成年に有害だと見なされ、携帯の閲覧制限(フィルタ)が掛かり問題となっているという話。
ネットスター株式会社とかいういち営利企業に、今後の日本のWebサイトの生殺与奪の権を握らせるらしい。〜中略〜 技術的に考えても、携帯向けかPC向けかで分けてデータベース化してるとは思えない。
実に同意。
フィルタリングの基準はソフトごとに違うし内容もブラックボックス。何の前触れもなく、フィルタのリストに入れられてしまうことも起こりうる。
そのうちmixiも対象になったりして・・。こりゃWebビジネスに影響が大ありっぽい。場合によっては "Google八分" 以上の怖さかも。とにかく、若くてやる気ある人たちの明るい展望をつぶすのだけはやめてほしいなあ。と思った。