acmecert: Fix cryptography bugs.
[utils.git] / anndata
diff --git a/anndata b/anndata
index 755c1bf..26e44db 100755 (executable)
--- a/anndata
+++ b/anndata
@@ -1,80 +1,49 @@
-#!/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";
-
+#!/usr/bin/python3
+
+import sys, os, getopt, ann
+
+def usage(out):
+    out.write("usage:\tanndata -h\n")
+    out.write("\tanndata -l PREFIX\n")
+    out.write("\tanndata [-b] {-d|NAME}\n")
+
+opts, args = getopt.getopt(sys.argv[1:], "hl:bd")
+lsn = None
+browse = False
+here = False
+for o, a in opts:
+    if o == "-h":
+        usage(sys.stdout)
+        sys.exit(0)
+    elif o == "-l":
+        lsn = a
+    elif o == "-b":
+        browse = True
+    elif o == "-d":
+        here = True
+
+if lsn is not None:
+    for s in ann.getlist(lsn):
+        sys.stdout.write("%s\n" % s.rawname)
+else:
+    if here:
+        nm = os.path.basename(os.getcwd())
+    else:
+        if len(args) < 1:
+            usage(sys.stderr)
+            sys.exit(1)
+        nm = args[0]
+    ls = ann.getlist(nm)
+    if len(ls) < 1:
+        sys.stderr.write("anndata: could not find %s\n" % nm)
+        sys.exit(1)
+    s = ls[0]
+    if len(ls) > 1:
+        sys.stderr.write("anndata: more than one match, using %s\n" % s.rawname)
+    if browse:
+        os.execlp("htmlview", "htmlview", s.url)
+    else:
+        sys.stdout.write("name:    %s\n" % s.name)
+        sys.stdout.write("vintage: %s\n" % s.vintage)
+        sys.stdout.write("genres:  %s\n" % ", ".join(s.genres))
+        sys.stdout.write("themes:  %s\n" % ", ".join(s.themes))