#!/usr/bin/env python # # check_los_altos.py - v0.2 # # Copyright (c) 2008 - Rich Burridge - Sun Microsystems Inc. # All Rights Reserved. # # Script to check each of my Amazon wish lists to see if any of the books are # now available at my local library. If they are, then write the book # information to stdout. # # Uses the pyAmazon Amazon Web Service API wrapper maintained by # Michael Josephson. # [http://www.josephson.org/projects/pyamazon/] # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. import ecs import smtplib import sys import urllib2 # ------ START OF CONFIGURABLE SECTION ---- # Amazon Access License Key. # amazonAccessKey = "XXXXXXXXXXXXXXXXXXXX" # Amazon Wishlist IDs. # amazonWishListIDs = [ "AAAAAAAAAAAAA", "BBBBBBBBBBBBB", "CCCCCCCCCCCC" ] # Url to access my local library system. The book ISBN is appended to it. # libraryURL = "http://146.74.92.11/ipac20/ipac.jsp?index=ISBNEX&term=" # ------ END OF CONFIGURABLE SECTION ------ def checkLibrary(book): ###sys.stderr.write("Checking Title: %s\n" % book.Item.Title) url = libraryURL + str(book.Item.ASIN) bookInfo = urllib2.urlopen(url) contents = bookInfo.read() if contents.find("Sorry, could not find anything matching") == -1: sys.stderr.write("Found in County Library: %s\n" % book.Item.Title) start = contents.find("Los Altos Library") if start != -1: sys.stderr.write("Los Altos Library has a copy\n") bookInfo = [ book.Item.Title ] end = contents.find("Add Copy to MyList", start) entry = contents[start:end] tokens = entry.split("<") for token in tokens: if token.startswith("a class"): text = token[token.find(">")+1:] bookInfo.append(text) if bookInfo[-1] == "In": sys.stderr.write("Currently IN\n") print ' '.join(bookInfo) def checkWishList(amazonWishListID): results = ecs.ListLookup('WishList', amazonWishListID, ResponseGroup='ListItems') for book in results: checkLibrary(book) if __name__ == "__main__": ecs.setLicenseKey(amazonAccessKey) for wishList in amazonWishListIDs: checkWishList(wishList) # ChangeLog # 8th April 2008 - 0.2 - richb - version using ecs.py. # 22nd February 2008 - 0.1 - richb - Initial version (using pyamazon).