From: fredrik Date: Sat, 23 Jul 2005 02:38:33 +0000 (+0000) Subject: Initial import. Can list series and map names to IDs and vice versa. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=5364a3ac72804eb88526d3700971fea23d3f0954;p=utils.git Initial import. Can list series and map names to IDs and vice versa. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@301 959494ce-11ee-0310-bf91-de5d638817bd --- diff --git a/anndata b/anndata new file mode 100755 index 0000000..755c1bf --- /dev/null +++ b/anndata @@ -0,0 +1,80 @@ +#!/usr/bin/perl -w + +use LWP::UserAgent; +use Getopt::Long; + +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")); + +if($options{"l"}) { + @list = getlist $ARGV[0]; + foreach $name (@list) { + print "$name\n"; + } + exit 0; +} + +unless($test = getid $ARGV[0]) { + printf STDERR "could not find $ARGV[0]\n"; + exit 1; +} + +print getnamefromid($test) . "\n"; +