As a joke dchud suggested that panizzi (the friendly neighborhood bot in #code4lib) should have a plugin for querying the Library of Congress Name Authority File that OCLC provides. The Name Authority File allows librarians the world over to use the same established names when cataloging books, etc. It would serve no purpose in irc, but it could be a good conversation piece…

I had goofed around writing a command line app about half a year ago so I figured it couldn’t be that hard to hack this into the infobot source code. However I guessed wrong…granted I only tried for 30 minutes or so.

Fortunately, python’s supybot was a different story. It’s more modern, has command line programs for configuring a supybot, has built in support for plugins – and has documentation. There is even a command line program supybot-newplugin that will ask a few questions and then autogenerate a template plugin module. All you have to do after that is add a method (with a particular signature given in the docs) which will then do the work and respond.


from urllib import urlencode
from urllib2 import urlopen
from elementtree.ElementTree import parse

class Naf(callbacks.Privmsg):   

    def naf(self,irc,msg,args):
        """<name>

        Lookup a personal name in the NAF file at OCLC
        """

        alcme = "http://alcme.oclc.org/eprintsUK/services/NACOMatch"
        name = privmsgs.getArgs(args)
        query = urlencode( { \
            "method"          : "getCompleteSelectedNameAuthority",
            "serviceType"     : "rest",
            "name"            : name,
            "maxList"         : "10",
            "isPersonalName"  : "true" } )

        url = urlopen( alcme + "?" + query)
        tree = parse(url)
        elem = tree.getroot()

        matches = elem.find("wordMatches").getchildren()
        irc.reply( matches[0][0].text )

As an added bonus along the way I got to try out ElementTree which has to be the nicest XML library I’ve ever used. It turned out to be a fun experiment, and will hopefully add to the merriment of the room.

22:03 < edsu> panizzi naf sigmund freud
22:03 < panizzi> edsu: Freud, Sigmund,--1856-1939