All | 43 Folders | Accessibility | BoingBoing | Books | Computer Related | Family | Films | General | Hacking | Hobbies | Humor | Java | Links | Omni | OpenSolaris | Puzzles and Games

« Previous day (Sep 2, 2007) | Main | Next day (Sep 4, 2007) »
20070903 Monday September 03, 2007

Be Informed When Used Amazon Books Are Available At Your Price

Like a lot of people who use Amazon, I have an Amazon wishlist. I use it mostly for keeping a record of which books I'd like to get.

It contains not only new books, but also items that are no longer in print and which I'm going to have to get used. Quite often I don't want to buy that item at the current used price, but if it gets a little cheaper than I might consider it (depending upon the quality).

I find myself continually going back to my Amazon wish list to see if the price is low enough yet. That's time consuming. It was time to automate the process.

I've written a couple of Python scripts that do all the work:

You are going to need a couple of other things to get this to work:

  1. An Amazon Access License key (developers token). To get this, you first have to get an Amazon Web Services Account. Go to their webpage. Over on the right side there is a "Your Web Services Account" button and just below that there is a Click here to Sign-Up link. Follow the sign-up steps and you will be emailed you all the information you need.

  2. The amazon.py file from the pyamazon distribution. pyAmazon was originally created by Mark Pilgrim, but is now being maintained by Michael Josephson. You should download the latest zip file of the distribution and unpack it.

Here's how to put it all together.

Create a new directory and put a copy of cheap_books.py and make_book_list.py in it. Also put a copy of amazon.py from the pyAmazon distribution into this directory.

Now you are going to create a books.py file which will contain a list of all the books on your Amazon wish list. You first need to make two changes to the make_book_list.py script. If you edit this file, you will see them in the CONFIGURABLE SECTION.

  1. Setup your Amazon Access License key. Replace "XXXXXXXXXXXXXXXXXXXX" with the key that Amazon sent you (in quotes).

  2. Setup your Amazon Wishlist ID. Replace "YYYYYYYYYYYY" with your wish list id (again in quotes). This is fairly easy to work out. In your favourite browser, go to your Amazon wish list page. If you look at the URL, you will see something like:

          http://www.amazon.com/gp/registry/wishlist/YYYYYYYYYYYY/...
          

    where "YYYYYYYYYYYY" is your wish list id. If the URL isn't in that form, click on the "Edit list information" link (near the top left of the page), and that should take you to another page where the URL is hopefully in the right format.

Now, from that directory you previously created, run the script:

% python ./make_book_list.py

If you've done everything correctly, there should now be a books.py file in that same directory. You will now need to edit that to setup the prices you are willing to pay for each item. Only prices below that value will be flagged and sent to you in the email that the cheap_books.py script sends out.

Note that it just looks for prices less than each given value as opposed to less than or equal to the given value. The intention there is reduce the number of prices you had to change. So if you are willing to pay $3.00 for a book, then set the price to $3.01. (I might revisit this. For me, I found that I ended up editing virtually every line in books.py anyway).

Before you run the cheap_books.py script, you are going to have to make a couple more changes. If you edit this file, you will see them in the CONFIGURABLE SECTION.

  1. Setup your Amazon Access License key. Replace "XXXXXXXXXXXXXXXXXXXX" with the key that Amazon sent you (in quotes).

  2. Setup your email address. Replace "somebody@somewhere.com" as appropriate.

Now again, from that directory you previously created, run the script:

% python ./cheap_books.py

If all goes well, you should have been sent an email, listing all the used Amazon books that are currently below your desired prices.

If you have problems with getting the script to send out the email (maybe a Python

socket.error: (111, 'Connection refused')

traceback), then see what I had to do in a previous post.

Now you've done all the hard work, you'll want to automate it so that the script gets run over night and all you'll have to do is check one new email each day. Cron can do that for you. To that end, I added the following line:

5 1 * * *       python $HOME/DVD/python/CheapBooks/cheap_books.py

with

% crontab -e

You'll need to adjust accordingly for your script location and the time you want the script run.

That's it. It's all a bit of a hack. But it took less than a day (including writing up this blog post). It's certainly going to save me some time. I'm sure the scripts can be improved. They certainly can be made more bullet proof. If I hack on it again, I'll try to adjust it so that the make_book_list.py script looks for an existing books.py file, and just adds in the new wish list items.

If you find bugs or have suggestions on how to improve the scripts, please let me know.

[]

[]

[]

[]

( Sep 03 2007, 11:24:04 AM PDT ) [Listen] Permalink Comments [1]