From 639d9800b021409ce4641a980fd720ff23ade428 Mon Sep 17 00:00:00 2001 From: fredrik Date: Tue, 9 Aug 2005 12:33:46 +0000 Subject: [PATCH] Separated into Anime::ANN. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@308 959494ce-11ee-0310-bf91-de5d638817bd --- anndata | 102 +++++++++++++++++++++++++--------------------------------------- 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/anndata b/anndata index 755c1bf..3cda2c2 100755 --- a/anndata +++ b/anndata @@ -1,80 +1,56 @@ #!/usr/bin/perl -w -use LWP::UserAgent; use Getopt::Long; +use Anime::ANN; -sub get -{ - my($uri, $ua, $res); - ($uri) = @_; - - $ua = LWP::UserAgent->new; - $ua->agent("ANNData/0.1"); - - $res = $ua->request(HTTP::Request->new("GET", "$uri")); - - die "could not fetch $uri\n" unless $res->is_success; - return $res->content; -} - -sub getlist -{ - my($name, $il, $html, @ret); - ($name) = @_; - - $il = uc(($name =~ /^(.)/)[0]); - $il = "9" if (!($il =~ /[A-Z]/)); - $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il"; - - # The only way to recognize entries that seems sure is to look - # after the "HOVERLINE" class. - - push @ret, $1 while $html =~ /.*([^<>]*$name[^<>]*)<\/FONT/ig; - - return(@ret); -} - -sub getid -{ - my($name, $il, $html, $url); - ($name) = @_; - - $il = uc(($name =~ /^(.)/)[0]); - $il = "9" if (!($il =~ /[A-Z]/)); - $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?list=$il"; - - # The only way to recognize entries that seems sure is to look - # after the "HOVERLINE" class. - - (($url) = ($html =~ /Anime News Network - ([^<]*)<\/TITLE>/)[0]); -} - -GetOptions(\%options, ("l")); +GetOptions(\%options, ("l=s", "b=s")); if($options{"l"}) { - @list = getlist $ARGV[0]; + @list = Anime::ANN::getlist($options{"l"}); foreach $name (@list) { print "$name\n"; } exit 0; } -unless($test = getid $ARGV[0]) { +if($options{"b"}) { + exec "htmlview", Anime::ANN::geturl(Anime::ANN::getid $options{"b"}); +} + +if(!defined($ARGV[0])) { + printf STDERR "usage: anndata NAME\n"; + exit 1; +} + +unless($id = Anime::ANN::getid $ARGV[0]) { printf STDERR "could not find $ARGV[0]\n"; exit 1; } -print getnamefromid($test) . "\n"; +$info = Anime::ANN::getseries $id; + +sub refdump +{ + my($ref, $ind); + ($ref, $ind) = @_; + if(!defined($ind)) { + $ind = 0; + } + + if(ref $ref eq "HASH") { + for $key (sort keys %{$ref}) { + print ((" " x $ind) . "$key: " . (" " x (20 - length $key)) . "(" . $ref->{$key} . ")\n"); + refdump($ref->{$key}, $ind + 1) if ref $ref->{$key}; + } + } elsif(ref $ref eq "ARRAY") { + for($i = 0; $i < @{$ref}; $i++) { + print ((" " x $ind) . "$i: " . $ref->[$i] . "\n"); + refdump($ref->[$i], $ind + 1) if ref $ref->[$i]; + } + } else { + print ((" " x $ind) . "Unknown ref: $ref\n"); + } +} +binmode STDOUT, ":utf8"; +refdump $info; -- 2.11.0