« 細かすぎて伝わらないlifehack選手権(Todo管理編) | Main | データベースを壊してしまってMTを再構築 »

誰どこ:フェニックスの『今ホームショップにいる人』を列挙する

ダーツマシンのフェニックスには今そのショップで1時間以内に投げた人を『今ホームショップにいる人』として表示できる機能があります。

これがPCから見る場合にはいちいちログインする必要がある上に登録カード1枚当たり一店舗しか見ることができなくて不便だったり、携帯サイトからだとブックマークはできるものの携帯のブラウザで何ページも見るのも面倒。

で、まとめて表示できるようにしてしまうスクリプトを書いてみました。

※制限事項:PCサイトからデータを取得している関係上、「1時間以内に投げた人」ではなく「30分以内に投げた人」だけが表示されます。携帯サイトからデータを取れるなら1時間以内に投げた人、ってできるんですけどね…。

なお、設置の際には表示したいホームショップを登録しているカードが必要です。設置例はこちらをご覧下さい。

エムロジック放課後プロジェクトさんのMovableType用EntityRefButtonプラグイン v0.0.2を使わせていただきました。超便利!

daredoko.cgi

#!/usr/local/bin/perl
#
# 『だれどこ?』:登録したカードで指定しているホームショップに今いるプレイヤーを一覧する
# 
# 2006/12/7 公開	/Daisuke Motohashi
#

use strict;
use warnings;
use LWP::UserAgent;
use CGI;#  qw(-debug);
use CGI::Carp qw(fatalsToBrowser);
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use HTML::Template;
use HTML::TableExtract;


#
#ユーザー設定(必須)
#

#フェニックスのアカウント情報
my @cardinfo	= (
		{
			shop => '川内ファンキータイム',
			id   => '',
			pw   => ''
		},

		{
			shop => '沖浜ファンキータイム',
			id   => '',
			pw   => ''
		}
	);

#プロキシの指定
my $proxy	= "";

#
# ↑ここまでユーザー設定 ここからシステム設定↓
#
my $charset		= "Shift_JIS";
my $cookie_file = "Cookie.txt";

# フェニックスPCサイトのURL
my $url_login = 'http://www.dartsjapan.jp/login.php';				#ログイン
my $url_homeshop = 'http://www.dartsjapan.jp/mypage_homeshop.php';	#いまどこ

# いまどこページ(mypage_homeshop.php)のテーブルで使われているヘッダー。
my @headers_mypage_homeshop = ('プレイヤーネーム', '性別', '年齢', 'Last Time', '状態' );
# その中から表示するヘッダを指定
my @th = ('プレイヤーネーム', '性別', 'Last Time');

#
# 設定ここまで
#
my $cgi = CGI->new;
print $cgi->header(-charset=>"$charset");

#  UserAgentの生成と、cookie_jarのセット 
my $cookie_jar  =  HTTP::Cookies->new(file  =>  $cookie_file,  autosave  =>  1,  ignore_discard  =>  1); 
my $ua = LWP::UserAgent->new; 
$ua->cookie_jar($cookie_jar); 
$ua->proxy(['http'] => $proxy);

my $template = HTML::Template->new_scalar_ref( template(), option => 'value');

my $line;
foreach my $card (@cardinfo){
	my @players = getActivePlayers($ua, $card->{id}, $card->{pw});
	$line .= "$card->{shop}";
	foreach my $p (@players){
		$line .= "";
		foreach my $key ( @th){
			if(defined $p->{$key}){
				$line .= "$p->{$key}\n";
			}
			else{
				$line .= "\n";
			}
		}
		$line .= "\n";
	}
}
$template->param(playerslist => $line);
print $template->output;

exit;

sub getActivePlayers{
	my ($ua, $id, $pw) = @_;

	# UserAgentを生成してログイン処理
	my $url      = $url_login;
	my %formdata = ('cardno' => $id, 'pw' => $pw);
	my $request  = POST($url, [%formdata]);
	my $res = $ua->request($request);

	# いまどこを取得
	$url = $url_homeshop;
	$res = $ua->get($url);
	my @players = parse_mypage_homeshop( $res->as_string );

	return @players;
}

#
#Phoenixいまどこページ(html)からのデータ抽出。ハッシュの配列を返す。
#
sub parse_mypage_homeshop{
	my $html = $_[0];

	my $te = HTML::TableExtract->new(
								depth     => 0,
								subtables => 0,
							);
	$te->parse( $html );

	my (@players);
	foreach my $ts ($te->tables) {
		foreach my $row ($ts->rows) {
			my %rowHash;
			for my $x (0..$#headers_mypage_homeshop){
				$rowHash{ $headers_mypage_homeshop[$x] } = $row->[$x] unless($row->[$x] && $row->[$x] eq "\xA0");
			}
			push(@players, \%rowHash) if($rowHash{'Last Time'} && $rowHash{'Last Time'} =~ /\d+:\d/);
	    }
	}
	return @players;
}


#テンプレートのリファレンスを返す。
sub template{
	my $temp = << "END_OF_TMPL";

Are there?


だれどこ

playersexLast Time

by ぶ (tenguyasiki.jp) END_OF_TMPL return \$temp; }

TrackBack

TrackBack URL for this entry:
http://tenguyasiki.jp/MT/mt-tb.cgi/32

Listed below are links to weblogs that reference 誰どこ:フェニックスの『今ホームショップにいる人』を列挙する:

» www crystalballsbingo com from www crystalballsbingo com
disbanded statues threader customizations chirp [Read More]

About

This page contains a single entry from the blog posted on 2006年12月07日 21:10.

The previous post in this blog was 細かすぎて伝わらないlifehack選手権(Todo管理編).

The next post in this blog is データベースを壊してしまってMTを再構築.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.31