Showing posts with label bottlenose. Show all posts
Showing posts with label bottlenose. Show all posts

17 December 2011

Making The New Amazon Product API Easy to Work With

I'm working on a new startup idea that I think will really rock the niche it's in and have been using the Amazon Product API a bunch.  They updated the API recently and now require you to send your associate id along with the query.

I've tried several xml parsing libraries and several Amazon libraries and have decided that the current combination of BeautifulSoup and bottlenose are what I enjoy working with the most.  I've been able to bang out tools for myself using this combo very quickly and have actually had fun building each one of them for a change.

import bottlenose
from BeautifulSoup import BeautifulSoup

# Replace these values with your correct info
AWS_KEY = 'key_goes_here'
SECRET_KEY = 'secret_goes_here'
ASSOCIATE_ID = 'your_associate_id_goes_here'

# Create a bottlenose object and initialize with our credentials
amazon = bottlenose.Amazon(AWS_KEY, SECRET_KEY)

# Query Amazon's Product API to perform an item lookup via the ASIN, returns the large response # group containing a ton of info, note that we must send the associate id now
response = amazon.ItemLookup(ItemId="B0018AFK38", ResponseGroup="Large", AssociateTag=ASSOCIATE_ID)

# Create a BS object from the XML response
soup = BeautifulSoup(response)

# A sample of the data that can be retrieved
print soup.find('itemid').string
print soup.find('formattedprice').string
print soup.find('detailpageurl').string
print soup.find('sku').string
print soup.find('content').string
print soup.find('title').string
print soup.find('department').string
print soup.find('smallimage').url.string
print soup.find('mediumimage').url.string
print soup.find('largeimage').url.string