TRD::Uranai - Today's Uranai Count down.


TRD-Uranai documentation Contained in the TRD-Uranai distribution.

Index


Code Index:

NAME

Top

TRD::Uranai - Today's Uranai Count down.

VERSION

Top

Version 0.0.2

SYNOPSIS

Top

Quick summary of what the module does.

Perhaps a little code snippet.

    use TRD::Uranai;

    my $uranai = TRD::Uranai::get( 'sjis' );
    TRD::Uranai::dump( $uranai );

EXPORT

Top

A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module.

FUNCTIONS

Top

get

    get today's uranai count down data.

data 'count' => 12, 'month' => '08', 'day' => '01', 'ranking' => [ { 'rank' => '01', 'image' => 'item/conste_sagittarius.gif', 'star' => 'いて座', 'text' => '大活躍', 'lucky' => [ { 'lucky' => 'カジュアルな服を着る', }, ], }, ],

dump

parseContents

getPage

AUTHOR

Top

Takuya Ichikawa, <trd.ichi at gmail.com>

BUGS

Top

Please report any bugs or feature requests to bug-trd-uranai at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=TRD-Uranai. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc TRD::Uranai




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=TRD-Uranai

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/TRD-Uranai

* CPAN Ratings

http://cpanratings.perl.org/d/TRD-Uranai

* Search CPAN

http://search.cpan.org/dist/TRD-Uranai

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


TRD-Uranai documentation Contained in the TRD-Uranai distribution.
package TRD::Uranai;

use warnings;
use strict;
use LWP::UserAgent;
use Jcode;

our $VERSION = '0.0.2';


#========================================================================
sub get {
	my $encode = (@_) ? shift : 'sjis';
	my $contents = &TRD::Uranai::getPage();
	my $uranai = &TRD::Uranai::parseContents( $contents, $encode );

	$uranai;
}

#========================================================================
sub dump {
	my $uranai = shift;

	print "count=". $uranai->{'count'}. "\n";
	print "month=". $uranai->{'month'}. "\n";
	print "day=". $uranai->{'day'}. "\n";
	foreach my $ranking ( @{$uranai->{'ranking'}} ){
		print "\trank=". $ranking->{'rank'}. "\n";
		print "\timage=". $ranking->{'image'}. "\n";
		print "\tstar=". $ranking->{'star'}. "\n";
		print "\ttext=". $ranking->{'text'}. "\n";
		foreach my $lucky ( @{$ranking->{'lucky'}} ){
			print "\t\tlucky=". $lucky->{'lucky'}. "\n";
		}
		print "\n";
	}
}

#========================================================================
sub parseContents {
	my $contents = shift;
	my $encode = shift;
	my $uranai;
	my $cnt = 0;

	if( $contents=~m#class="day">(\d+)·î(\d+)Æü</td># ){
		$uranai->{'month'} = $1;
		$uranai->{'day'} = $2;
	}
	my @ranks;
	push( @ranks, [$1, $2] ) while( $contents=~s/<table width="306" height="\d+" border="0" cellpadding="0" cellspacing="0" background="item\/rank(\d+)\.gif">(.*?)<\/table>//is );

	foreach my $row ( @ranks ){
		my $item;
		my( $rank, $part ) = @{$row};
		$item->{'rank'} = $rank;
		if( $part=~s# valign="top"><img src='(.+?)' alt='(.+?)' hspace='3'## ){
			$item->{'image'} = $1;
			my $star = $2;
			$star = Jcode::convert( $star, $encode, 'euc' );
			$item->{'star'} = $star;
		} elsif( $part=~s# valign="top"><span class="text"><img src='(.+?)' alt='(.+?)' hspace='3'## ){
			$item->{'image'} = $1;
			my $star = $2;
			$star = Jcode::convert( $star, $encode, 'euc' );
			$item->{'star'} = $star;
		}
		if( $part=~s# class="text">(.+?)</td>## ){
			my $text = $1;
			$text = Jcode::convert( $text, $encode, 'euc' );
			$item->{'text'} = $text;
		}
		while( $part=~s# class="lucky">(.+?)</td>## ){
			my $l = $1;
			$l = Jcode::convert( $l, $encode, 'euc' );
			my $lucky = {'lucky' => $l };
			push( @{$item->{'lucky'}}, $lucky );
		}

		push( @{$uranai->{'ranking'}}, $item );

		$cnt += 1;
	}

	$uranai->{'count'} = $cnt;

	$uranai;
}

#========================================================================
sub getPage {
	my $retval = '';
	my $url = 'http://www.fujitv.co.jp/meza/uranai/index.html';
	my $ua = LWP::UserAgent->new;
	$ua->agent( 'Mozilla' );
	my $request = HTTP::Request->new( GET=>$url );
	my $res = $ua->request( $request );
	if( $res->is_success ){
		$retval = Jcode::convert( $res->content, 'euc', 'sjis' );
	}

	$retval;
}

1; # End of TRD::Uranai