Here’s a simple Python example, using an approach my colleague Rick Brannan developed, for extracting the ISBN numbers of resources in your Libronix library. Why? So you can upload them to LibraryThing. Here’s the deal: LibraryThing is a great social bookmarking service for bibliophiles, where you can find out who else has the same books you do and use that to discover common interests, popular titles, reviews, etc. A lifetime membership for LibraryThing is only $25, which seems like a bargain. But the other cost of admission is entering your library information. For dead tree books, you can use a CueCat scanner with the barcode to get a list of ISBN numbers (which you cue up so LibraryThing can look up and import the other metadata). But for electronic books like those in Libronix, how do you get the ISBNs? The best Libronix packages like Scholar’s Gold and Silver have thousands of resources, and looking each one up by hand is a daunting task.
LDLSOM to the rescue! The following snippet of Python code goes through each resource in your library, extracts the metadata (you can view this in the application with Help > About This Resource), and prints out the ISBN numbers for resources that have them (that’s a couple hundred for the version i have here at work). This assumes you have a standard Python installation (i use the excellent one from ActiveState) and one additional package for XML parsing: see the comments in the code. Unlike Rick’s version, there’s no user interface or other niceties: it just prints out the list. While i don’t want to provide basic Python tutorials (there are plenty of great ones out there already), if you know Python but can’t get this working, let me know (sean at logos here’s-the-dot com) and i’ll try to help. (i can’t get the indentation right, which Python cares about but WordPress loves to mangle: download the code here.)
If you use this to load your LibraryThing catalog, let me suggest you tag your books with “libronix“, which seems to be the most popular LIbraryThing tag at present for Libronix titles (though “ldls” and “Libronix ebook” are also in use).
import win32com.client # requires 4suite.org XML processing library, available from # http://4suite.org/?xslt=downloadproduct.xslt&show=http%3A%2F%2F4suite.org%2Fdata%2Fsoftware%2F4Suite or # http://sourceforge.net/project/showfiles.php?group_id=39954 from Ft.Xml import Parse def toascii(str): """Silly hack for producing a mostly correct ASCII version of a Unicode string.""" return str.encode('ascii', 'xmlcharrefreplace') def main(): # get a handle for the application, starting it if necessary ldls = win32com.client.Dispatch('LibronixDLS.LbxApplication') # for each resource, get the DC metadata in XML, parse it, and extract # the ISBN number (if any) for res in ldls.Librarian.Information.Resources: metadata = ldls.Librarian.OpenResourceMetadata(res.ResourceID) dcm = metadata.XML.selectSingleNode("dc-metadata").xml # presumably any unicode characters won't be in the ISBN dcmobj = Parse(toascii(dcm)) isbnnode = dcmobj.xpath(u"/dc-metadata/dc-element[@name='dc.identifier:isbn']/text()") if isbnnode: print '%st"%s"' % (isbnnode.nodeValue, toascii(ldls.Librarian.GetResourceTitle(res.ResourceID))) if __name__ == "__main__": main()