X-Git-Url: http://dolda2000.com/gitweb/?p=utils.git;a=blobdiff_plain;f=anndata;h=7ed3e1373a26ba3482207d113b5bc03db44e503c;hp=755c1bf340475678549f54d9c45803e166947611;hb=f7bd9b51138dbccb7cc2fd27f07ef66d5d2d79cf;hpb=5364a3ac72804eb88526d3700971fea23d3f0954 diff --git a/anndata b/anndata index 755c1bf..7ed3e13 100755 --- a/anndata +++ b/anndata @@ -1,80 +1,70 @@ #!/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")); +binmode STDOUT, ":utf8"; +GetOptions(\%options, "l=s", "b=s", "d") || exit 1; 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]) { +$browse = ""; +if($options{"b"}) { + $browse = $options{"b"}; +} elsif($options{"d"}) { + $browse = `basename "\$(pwd)"`; +} +if($browse) { + $id = Anime::ANN::getid $browse; + if(defined($id)) { + exec "htmlview", Anime::ANN::geturl($id); + } else { + printf STDERR "could not find " . $browse . "\n"; + exit 1; + } +} + +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]; + } + } elsif(ref $ref eq "SCALAR") { + print ((" " x $ind) . $$ref . "\n"); + } else { + print ((" " x $ind) . "Unknown ref: $ref\n"); + } +} +refdump $info;