#!/usr/bin/env python # # make_book_list.py - v0.3 # # Copyright (c) 2007-2008 - Rich Burridge - Sun Microsystems Inc. # All Rights Reserved. # # Usage: python make_book_list # # Script to create a list of the books on an Amazon wish list. # Each line is a list which consists of three items: # 1/ The book ASIN # 2/ The current lowest used price. # 3/ The book title # # This list (which is written to a file called "books.py" in the # current directory) will be used as input to the cheap_books.py script. # That script only needs the first two items in each list entry. # The other one is there to help you know which book is which. # # Before you run the cheap_books.py script, you will need to adjust # the current used price values to be the price you are willing to pay # for that book. In other words, books with a used price below that value # will be flagged by the cheap_books.py script. # # Uses PyAWS, a Python wrapper for the latest Amazon Web Service. # Kun Xi. # [http://pyaws.sourceforge.net/] # # 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 time # ------ START OF CONFIGURABLE SECTION ---- # Amazon Access License Key. # amazonAccessKey = "XXXXXXXXXXXXXXXXXXXX" # Amazon Wishlist ID. # amazonWishListID = "YYYYYYYYYYYY" # ------ END OF CONFIGURABLE SECTION ------ def writeBookInfo(bookFile, book): print "Processing Title: ", book.Item.Title results = ecs.ItemLookup(book.Item.ASIN, ResponseGroup='Large') try: usedPrice = results[0].OfferSummary.LowestUsedPrice.FormattedPrice except: usedPrice = "None used" bookFile.writelines(" [ \"" + str(results[0].ASIN) + \ "\", \"" + str(usedPrice) + \ "\", \"" + (''.join([ x[0] for x in book.Item.Title ])) + \ "\" ],\n") def processResults(bookFile, results): for book in results: writeBookInfo(bookFile, book) def checkWishList(amazonWishListID): bookFile = open("books.py", "w") bookFile.writelines("list_of_books = [\n") results = ecs.ListLookup('WishList', amazonWishListID, ResponseGroup='ListItems') processResults(bookFile, results) bookFile.writelines("]\n") bookFile.close() if __name__ == "__main__": ecs.setLicenseKey(amazonAccessKey) checkWishList(amazonWishListID) # ChangeLog # 9th April 2008 - 0.3 - richb - version using ecs.py. # 25th February 2008 - 0.2 - richb - Add 1 second sleep to prevent 503 errors. # 3rd September 2007 - 0.1 - richb - Initial version.