<commit_before>import amazonproduct
from lxml import etree

# 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):
	try:
		root = amazon.item_search("Music", Artist=artist, Title=album, ResponseGroup="Small,ItemAttributes,Images,Offers", AssociateTag = keys[2], MerchantId = "Amazon", Condition = "New")
	except amazonproduct.errors.NoExactMatchesFound:
		return _empty(album)

	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
		ret["image"] = item.LargeImage.URL
		#ret["lowest_new"] = int(item.OfferSummary.LowestNewPrice.Amount)
		ret["amazon_new"] = int(item.Offers.Offer.OfferListing.Price.Amount)
		return ret
	return _empty(album)<commit_msg>Cope if we don't have a picture for a CD<commit_after>import amazonproduct
from lxml import etree

# 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):
	try:
		root = amazon.item_search("Music", Artist=artist, Title=album, ResponseGroup="Small,ItemAttributes,Images,Offers", AssociateTag = keys[2], MerchantId = "Amazon", Condition = "New")
	except amazonproduct.errors.NoExactMatchesFound:
		return _empty(album)

	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)
{'fraction_non_alphanumeric': 0.14832962138084632, 'fraction_numerical': 0.0035634743875278397, 'mean_word_length': 5.221606648199446, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1235952', 'n_tokens_mistral': 812, 'n_tokens_neox': 773, 'n_words': 176}