Build notes for Amazon AADL Linky
I found some code - Carrick Mundell's "Amazon SPL Linky" - that adds links from the amazon.com catalog into the Seattle Public Library catalog. After an evening of hacking on it, I came up with the "Amazon AADL Linky", which does the same thing for the Ann Arbor District Library catalog.
(Update: Jon Udell pointed out quite correctly that Carrick's version is derived from Jon's original Library Lookup Greasemonkey script, which in turn is derived from Jon's Library Lookup bookmarklet. Thanks Jon!)
I did this after a lunch (a very mild Thai shrimp curry) with Mr. Findability, Peter Morville, who said that he doesn't use the library as much as he might because it's so easy to buy books from Amazon. & so you figure, what would it take to make it that much easier to use the library? Put it in the middle of Amazon.
Here are some build notes of what I did, which should help the next person do this for whatever system they want to do it for, and should help me remember what I did if it needs to happen again.
First, don't start from my copy of the code, start from the original script. Carrick is maintaining it and doing the necessary changes to keep it working with Firefox and Greasemonkey. You'll want to use some kind of source code control system to keep track of you changes, so that when a new release comes out you can patch in what you did and not have to figure it all out again.
The script has a number of variables at the top. I won't go through all of them, but some critical ones to start:
libraryUrlPattern (and in my copy libraryUrlPatternTrailer) are strings that represent how to do a search for a known ISBN in your catalog. Every catalog has a slightly different syntax for doing ISBN lookups, and the easiest way to find it is to go into your "advanced search" and do a lookup, copy out the URL you find and decode the results. Try to trim away any extraneous stuff like a session id.
notFound is a pattern that matches the screen that gets returned when your catalog has no holdings for that item. The catalog might try to be extra-helpful and tell you about all kinds of other things it has, but you want to zero in on the bit of bad news.
libraryAvailability, libraryOnOrder, libraryInProcess, libraryHolds, and libraryDue are all patterns that match the state of the system regarding hold status. Find items in each of those states - a book that's in, a book on order, a book in processing, a book with lots of holds, and a book that's due back - and determine the unique string that signals that state. You might need to be clever about it, because e.g. the AADL has "Zoom Lends" which means you can pay to get "S is for Silence" right away if you want to bypass the hold queue. I don't count that as "Available".
If you're not familiar with regular expressions, this is not the place to teach them. Know that \d matches a digit, \- matches a -, and a phrase in (parenthesis) can be returned as a match string.
On to the logic of the program. The program tests for a number of conditions in order to figure out what the state of the world is with that title. I had to reorganize the if/elseif clauses a little bit to get the "S is for Silence" + Zoom Lends case right, so that it looked for hold status before it looked for available copies. I'm not entirely happy with how my code picks out the due date, because that's not terribly meaningful with lots of copies out and lots on hold, and the catalog doesn't predictably return the "first" due date first. You might be able to use it as is.
You'll need to adjust the very top stanza, the @namespace part, to reflect the server you're putting the code on. Save it somewhere it can be downloaded. It requires Firefox 1.5 and a current Greasemonkey, which are easy enough to install.
To use it, fire up amazon.com and start browsing. When you hit a book title, you should see the status of it in your catalog appropriately highlighted under the title. Click through to confirm, and if it's not quite right iterate until it is right. The two things I needed to do iteratively were to adjust the regular expressions and to resort the test order.
Hope this helps.
Technorati Tags: aadl, amazon, greasemonkey, library, librarylookup, jonudell, library, library2.0
Hi Ed! You rule, but you already knew that. I've stolen your script and modified it to work with our (SJCPL) catalog. Do you mind if I put it out there? I've left the superpatron url in. :)
Posted by: maire | 13 January 2006 at 09:18 AM
and now i show my excitment at new shiny things. I re-read through your post. I know you say not to start with your code, but it's so good! and I'm pretty new at this greasemonkey stuff. anyhoo, thanks again for posting this!
Posted by: maire | 13 January 2006 at 09:25 AM
Maire, absolutely, put it out there to use. Jon Udell gets the original idea and code credit.
You might want to register your copy of it at http://userscripts.org (free) which puts it somewhere people can find it who would be looking.
Ed
Posted by: Edward Vielmetti | 13 January 2006 at 01:38 PM
Thanks Ed! I'm making a userscripts account now.
Posted by: maire | 13 January 2006 at 01:46 PM
Jon is mostly correct. I derived my code from a script I found at snarfed.com, which I mention and link to in my original post about the script. Jon's script was the inspiration and basis for the script at snarfed.com.
Posted by: Carrick Mundell | 13 January 2006 at 07:13 PM