#!/usr/bin/env python # # make_book_list.py - v0.2 # # 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 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 amazon import time # ------ START OF CONFIGURABLE SECTION ---- # Amazon Access License Key. # amazonAccessKey = "1RNG79N9RF6EHY0KEJ02" # Amazon Wishlist ID. # amazonWishListID = "BLWCCRW27L6J" # ------ END OF CONFIGURABLE SECTION ------ # Maximum number of results returned per page. # MAX_RESULTS = 10 def writeBookInfo(bookFile, book): print "Processing Title: ", book.ProductName if "UsedPrice" in dir(book): usedPrice = book.UsedPrice else: usedPrice = "None used" bookFile.writelines(" [ \"" + str(book.Asin) + \ "\", \"" + str(usedPrice) + \ "\", \"" + (''.join([ x[0] for x in book.ProductName ])) + \ "\" ],\n") def processResults(bookFile, books): for book in books: writeBookInfo(bookFile, book) def checkWishList(amazonWishListID): bookFile = open("books.py", "w") bookFile.writelines("list_of_books = [\n") pageNo = 1 finished = False while not finished: results = amazon.searchByWishlist(amazonWishListID, page=pageNo) time.sleep(1) if len(results) != 0: processResults(bookFile, results) if len(results) == MAX_RESULTS: pageNo += 1 else: finished = True bookFile.writelines("]\n") bookFile.close() if __name__ == "__main__": amazon.setLicense(amazonAccessKey) checkWishList(amazonWishListID) # ChangeLog # 25th February 2008 - 0.2 - richb - Add 1 second sleep to prevent 503 errors. # 3rd September 2007 - 0.1 - richb - Initial version.