Initial import. Can list series and map names to IDs and vice versa.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sat, 23 Jul 2005 02:38:33 +0000 (02:38 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sat, 23 Jul 2005 02:38:33 +0000 (02:38 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@301 959494ce-11ee-0310-bf91-de5d638817bd

anndata [new file with mode: 0755]

diff --git a/anndata b/anndata
new file mode 100755 (executable)
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 =~ /<A\s.*CLASS=HOVERLINE\s.*>.*<FONT.*>([^<>]*$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 =~ /<A\s.*CLASS=HOVERLINE\s.*HREF=\"([^\"]+)\".*$name/i)) || return;
+    
+    return((($url =~ /\?id=(\d+)$/)[0]));
+}
+
+sub getnamefromid
+{
+    my($id, $html);
+    ($id) = @_;
+    
+    $html = get "http://www.animenewsnetwork.com/encyclopedia/anime.php?id=$id";
+    
+    return(($html =~ /\<TITLE\>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";
+