Wed, Nov 28, 2007, 1:32am Automator Joy: Amazon Wish List to Text
Programming » Automator
(Last updated: Wed, Aug 19, 2009, 1:29pm)
oday I had a 40% off coupon at Borders. I also have tons of things on my many Amazon wish lists*. What I wanted was a way to quickly print out my wish list, but without all the crap that Amazon has on their webpage. All I want is the title, author(s) and price. No graphics, no tables, &tc. I had about an hour before I had to head out the door. I thought: This is a job for Automator, surely. And it was.

With time to spare, I found the item to grab webpages, figured out how it parse webpages into paragraphs, and then monkeyed with a custom python script enough to make a reasonable list that was ready to print. Worked great. When I got home, I added a few extra things to clean up the text some more and fix a bug or two. Much later, I made sure it worked if you were an anonymous user or a logged in user, and made it work with CD/DVDs, and other products.

You can download the script: Amazon Wish List to Text (let's call this version 1.0).

Update 8/19/2009: In case anyone is wondering: This version no longer works due to a formatting change at Amazon. I'll sit down and write a 2.0 version if you don't write one first and post it to the discussion below.

To get it set up for easy access:

  1. Enable the script menu, if it's not already there (in the upper right hand side of the menu bar): Run the AppleScript Utility, often found in the /Applications/AppleScript folder. Check the "Show Script menu in menu bar" checkbox. Quit the AppleScript Utility program.
  2. Open the Safari scripts folder, by going to Open Scripts Folder > Open Safari Scripts Folder in the scripting menu.
  3. Place in script, and close the scripts folder window.

At least currently, this only works when viewing lists in the "Normal"-sized view.

The workflow requires that the wish list Safari window be the foremost Safari window, and it will append the text into the foremost TextEdit document. I did that so I could allow multi-page wish lists to keep appending to the same TextEdit doc until I was done. If TextEdit isn't running, it'll open and start a new document with the text.

The output looks like the following example (although there are no line numbers in the real output):
  1 Cephalopod Behaviour (Hanlon, Messenger)
2 The Evolution of Thought: Evolutionary Origins of Great Ape Intelligence (Russon, Begun) $127
3 CD: This American Life: Lies Sissies & Fiascoes (Ira Glass) $13
4 Weber Q 200 Portable Propane Grill, Silver Series (Weber) $179
5 IRoast2 40011 5-2/7-Ounce Coffee-Bean Roaster, Black (Hearthware, INC) $182
6 Rock 'n' Roll: A New Play (Tom Stoppard) $10

In the current version of the script, multiple authors are only listed by last name, but single authors get their full name. Prices are rounded to the nearest whole dollar, if available, and there's a 120 character line limit (the whole line, price, authors and all). You can change the length easily at the top of the script. Just double click on the script to bring up Automator. Change the value, then save.

The script is editable, so fix bugs, modify to your taste, etc. The heart of it is a simple Python script. If you want to post fixes or improvements to the script, by all means do so and I'll incorporate stuff. It's provided as-is as freeware. (As such, I take no responsibility if this does any harm. Use at your own risk.)

* I only recently decided to break up my list of over a hundred unorganized items on my wishlist into many sub-wishlists, giving meaningful names to each list. My main worry is that almost no one who goes to see someone's wishlists thinks to look at the left of the page to see if that person has other wishlists that are public. I hope Amazon fixes this.

  • Ramon (Sat, January 19th, 2008, 5:03pm UTC)
    Great idea! Any chance of posting the Python script on its own? I'd like to get this running on Windows as well…

  • Jeff (Sat, January 19th, 2008, 9:00pm UTC)
    Sure thing. Here's what I have and feel free to improve. (The lineLengthMaximum variable at the top determines the max width ofthe text edit output, which I just set to 120 because it seemed about right.)

    ( python )
      1 import sys, string
    3 lineLengthMaximum = 120
    5 authorReplacements = {
    6 ' (Author)' : '', ' (Editor)' : '', ' (Translator)' : '',
    7 ', et al.' : '', 'by ' : '', 'DVD ' : '', '~ ' : '',
    8 }
    9 titleReplacements = {
    10 'Second Edition' : '2nd ed.',
    11 'Third Edition' : '3rd ed.',
    12 'Fourth Edition' : '4th ed.',
    13 }
    15 lines = []
    16 for f in sys.stdin:
    17 lines.append( f.strip() )
    19 def multiReplace( text, replaceDictionary ):
    20 for key in replaceDictionary.keys():
    21 text = text.replace( key, replaceDictionary[key] )
    22 return text
    24 blocks = string.join( lines, '\n' ).split( 'RECEIVED' )
    25 blocks[0] = blocks[0].split('\n\n\n')[-1]
    27 for block in blocks[:-1]:
    28 price = ''
    29 partsA = block.split( '\n\n\n' )[-1].split( '\n\n' )
    30 partsB = ''
    32 for part in partsA:
    33 if ('DESIRED' not in part and 'PRIORITY' not in part) or 'unavailable' in part:
    34 partsB = part.strip()
    36 partsC = partsB.split( '\n' )
    37 title, authors = partsC[:2]
    39 if '~' in authors:
    40 if 'DVD' in authors:
    41 title = 'DVD: ' + title
    42 else:
    43 title = 'CD: ' + title
    45 title = multiReplace( title, titleReplacements )
    46 authors = multiReplace( authors, authorReplacements )
    48 for part in partsC:
    49 if '$' in part:
    50 priceValue = part.split( '$' )[1]
    51 price = ' $' + str( int( round( eval( priceValue ) ) ) )
    53 if ',' in authors:
    54 authorsToShow = authors.split( ',' )[0].split( ' ' )[-1]
    55 for author in authors.split( ',' )[1:]:
    56 authorsToShow += ', ' + author.split( ' ' )[-1]
    57 else:
    58 authorsToShow = authors.strip()
    60 priceLength = len( price ) or -1
    62 fullLine = title + ' (' + authorsToShow + ')' + price
    64 if len( fullLine ) > lineLengthMaximum — 2:
    65 titleLength = lineLengthMaximum — 7 — len( authorsToShow ) — priceLength
    66 title = title[:titleLength] + '...'
    68 print title + ' (' + authorsToShow + ')' + price
    70 print

  • James Pearce (Thu, August 28th, 2008, 8:34am UTC)
    What a great use for Automator! I modified the script on line 68 to not print the price, and I used the output to give to people as a books wishlist via email. Much easier for them to read than browsing 10 pages of Amazon with US$ all over it (I'm in Australia).

    Thanks again Jeff!

  • Braidwood (Mon, March 16th, 2009, 7:36pm UTC)

    This is just what I need. ITs the first time I've used automator and I managed to followed your three "easy access" set up instructions, but I don't know what to do next. How do I make the script run? I've tried choosing print from the Safari File menu, but that didn't work. Hmm….

  • Jeff (Mon, March 16th, 2009, 8:37pm UTC)
    Braidwood, in the upper-right hand corner of your screen you should see a little icon that represents your Applescript Menu (I'll include a screenshot here).

    Selecting the item shown there should run the script. After you select / run it, switch to TextEdit and see if there isn't a plain text list of what is shown for your Amazon wish list in your browser window.

    Keep in mind that it will append the text to whatever is the currently opened document in TextEdit. When making a fresh list, I usually open a blank document, then switch to Safari to run the script.

  • Jeff (Wed, August 19th, 2009, 1:30pm UTC)
    For those following the RSS feed on this page, Amazon changed the formatting in the wish list page, so a new version of the script is in order. I'll sit down at write it when I get some spare time (unless someone wants to write it first and post it here!).

Leave a comment