Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (39 sloc) 1.253 kB
import amazonproduct
from lxml import etree
from time import sleep
# AWS, then SECRET, then associate id
keys = [x.strip() for x in file(".amazonkey").readlines()]
amazon = amazonproduct.API(keys[0], keys[1], "uk")
def _empty(album):
ret = {}
ret["title"] = album
ret["url"] = None
ret["image"] = None
ret["amazon_new"] = None
return ret
def searchByTitle(artist, album):
while True:
try:
root = amazon.item_search("Music", Artist=artist, Title=album, ResponseGroup="Small,ItemAttributes,Images,Offers", AssociateTag = keys[2], MerchantId = "Amazon", Condition = "New")
break
except amazonproduct.errors.NoExactMatchesFound:
return _empty(album)
except BaseException, e:
print "Other exception while doing amazon", e
sleep(3)
page = root.page(1)
ret = {}
for item in page.Items.Item:
binding = item.ItemAttributes.Binding
if binding!="Audio CD":
continue
ret["title"] = item.ItemAttributes.Title
ret["url"] = item.DetailPageURL
if hasattr(item, "LargeImage"):
ret["image"] = item.LargeImage.URL
else:
ret["image"] = None
#ret["lowest_new"] = int(item.OfferSummary.LowestNewPrice.Amount)
ret["amazon_new"] = int(item.Offers.Offer.OfferListing.Price.Amount)
return ret
return _empty(album)
Jump to Line
Something went wrong with that request. Please try again.