本文整理汇总了Python中amazon.api.AmazonAPI.browse_node_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python AmazonAPI.browse_node_lookup方法的具体用法?Python AmazonAPI.browse_node_lookup怎么用?Python AmazonAPI.browse_node_lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazon.api.AmazonAPI
的用法示例。
在下文中一共展示了AmazonAPI.browse_node_lookup方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AmazonScraper
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
class AmazonScraper(object):
def __init__(self, access_key, secret_key, associate_tag, *args, **kwargs):
self.api = AmazonAPI(access_key, secret_key, associate_tag, *args, **kwargs)
def reviews(self, ItemId=None, URL=None):
return Reviews(self, ItemId, URL)
def review(self, Id=None, URL=None):
return Review(self, Id, URL)
def lookup(self, URL=None, **kwargs):
if URL:
kwargs['ItemId'] = extract_asin(URL)
result = self.api.lookup(**kwargs)
if isinstance(result, (list, tuple)):
result = [Product(p) for p in result]
else:
result = Product(result)
return result
def similarity_lookup(self, **kwargs):
for p in self.api.similarity_lookup(**kwargs):
yield Product(p)
def browse_node_lookup(self, **kwargs):
return self.api.browse_node_lookup(**kwargs)
def search(self, **kwargs):
for p in self.api.search(**kwargs):
yield Product(p)
def search_n(self, n, **kwargs):
for p in self.api.search_n(n, **kwargs):
yield Product(p)
示例2: generate_csv
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
def generate_csv():
# initialize amazon api with access key, secret key, and associate tag
amazon = AmazonAPI('AKIAJPT5M67Z5DB6R3XA', 'P0ekhRiDVDC2xeJa4fZz1P5qHY/B2Qig71G6wZB3', 'thedeepdark-20')
print("Querying amazon API")
# returns available book subjects
subjects = amazon.browse_node_lookup(BrowseNodeId=1000)
f = open('data.csv', 'wb')
writer = csv.writer(f)
print("\tReturned with " + str(len(subjects[0].children)) + " subjects")
# creates books and author lists
for subject in subjects:
for genre in subject.children:
# skip calendar entries
if genre.name.text == 'Calendars': continue
# returns first 1000 entries in each subject
# Amazons api limits the number of return pages to 10
# with 10 items on each for a maximum of 100 items
books = amazon.search_n(100, Condition='All', BrowseNode=genre.id, SearchIndex='Books', MaxQPS=0.9)
print("Queried " + genre.name + ", returned " + str(len(books)) + " books")
failed = 0
for book in books:
b_isbn = book.isbn
b_title = book.title
b_pub_date = str(book.publication_date)
b_genre = genre.name
b_publisher = book.publisher
b_list_price = book.list_price[0]
b_price = book.price_and_currency[0]
if len(book.authors) == 0:
break
book_item = [b_isbn, b_title, book.authors[0], b_pub_date, b_publisher, b_genre, b_list_price, b_price]
for x in range(len(book_item)):
if isinstance(book_item[x], str):
book_item[x] = unicode(book_item[x], 'utf-8')
try:
writer.writerow(book_item)
except UnicodeEncodeError:
failed += 1
print("\tDone processing books, failed to convert unicode characters " + str(failed) + " times")
time.sleep(5)
示例3: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
#.........这里部分代码省略.........
"""
amazon = AmazonAPI(
AMAZON_ACCESS_KEY,
AMAZON_SECRET_KEY,
AMAZON_ASSOC_TAG,
region="UK"
)
assert_equals(amazon.api.Region, "UK", "Region has not been set to UK")
products = amazon.search(Keywords='Kindle', SearchIndex='All')
currencies = [product.price_and_currency[1] for product in products]
assert_true(len(currencies), "No products found")
is_gbp = 'GBP' in currencies
assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though")
def test_similarity_lookup(self):
"""Test Similarity Lookup.
Tests that a similarity lookup for a kindle returns 10 results.
"""
products = self.amazon.similarity_lookup(ItemId="B0051QVF7A")
assert_true(len(products) > 5)
def test_product_attributes(self):
"""Test Product Attributes.
Tests that all product that are supposed to be accessible are.
"""
product = self.amazon.lookup(ItemId="B0051QVF7A")
for attribute in PRODUCT_ATTRIBUTES:
getattr(product, attribute)
def test_browse_node_lookup(self):
"""Test Browse Node Lookup.
Test that a lookup by Brose Node ID returns appropriate node.
"""
bnid = 2642129011
bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0]
assert_equals(bn.id, bnid)
assert_equals(bn.name, 'eBook Readers')
assert_equals(bn.is_category_root, False)
def test_obscure_date(self):
"""Test Obscure Date Formats
Test a product with an obscure date format
"""
product = self.amazon.lookup(ItemId="0933635869")
assert_equals(product.publication_date.year, 1992)
assert_equals(product.publication_date.month, 5)
assert_true(isinstance(product.publication_date, datetime.date))
def test_single_creator(self):
"""Test a product with a single creator
"""
product = self.amazon.lookup(ItemId="B00005NZJA")
creators = dict(product.creators)
assert_equals(creators[u"Jonathan Davis"], u"Narrator")
assert_equals(len(creators.values()), 1)
def test_multiple_creators(self):
"""Test a product with multiple creators
"""
product = self.amazon.lookup(ItemId="B007V8RQC4")
示例4: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
#.........这里部分代码省略.........
"""
amazon = AmazonAPI(
AMAZON_ACCESS_KEY,
AMAZON_SECRET_KEY,
AMAZON_ASSOC_TAG,
region="UK"
)
assert_equals(amazon.api.Region, "UK", "Region has not been set to UK")
products = amazon.search(Keywords='Kindle', SearchIndex='All')
currencies = [product.price_and_currency[1] for product in products]
assert_true(len(currencies), "No products found")
is_gbp = 'GBP' in currencies
assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though")
def test_similarity_lookup(self):
"""Test Similarity Lookup.
Tests that a similarity lookup for a kindle returns 10 results.
"""
products = self.amazon.similarity_lookup(ItemId=TEST_ASIN)
assert_true(len(products) > 5)
def test_product_attributes(self):
"""Test Product Attributes.
Tests that all product that are supposed to be accessible are.
"""
product = self.amazon.lookup(ItemId=TEST_ASIN)
for attribute in PRODUCT_ATTRIBUTES:
getattr(product, attribute)
def test_browse_node_lookup(self):
"""Test Browse Node Lookup.
Test that a lookup by Brose Node ID returns appropriate node.
"""
bnid = 2642129011
bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0]
assert_equals(bn.id, bnid)
assert_equals(bn.name, 'eBook Readers')
assert_equals(bn.is_category_root, False)
def test_obscure_date(self):
"""Test Obscure Date Formats
Test a product with an obscure date format
"""
product = self.amazon.lookup(ItemId="0933635869")
assert_equals(product.publication_date.year, 1992)
assert_equals(product.publication_date.month, 5)
assert_true(isinstance(product.publication_date, datetime.date))
def test_single_creator(self):
"""Test a product with a single creator
"""
product = self.amazon.lookup(ItemId="B00005NZJA")
creators = dict(product.creators)
assert_equals(creators[u"Jonathan Davis"], u"Narrator")
assert_equals(len(creators.values()), 2)
def test_multiple_creators(self):
"""Test a product with multiple creators
"""
product = self.amazon.lookup(ItemId="B007V8RQC4")
示例5: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
#.........这里部分代码省略.........
assert_equals(product.browse_nodes[0].id, 2642129011)
assert_equals(product.browse_nodes[0].name, 'eBook Readers')
def test_batch_lookup(self):
"""Test Batch Product Lookup.
Tests that a batch product lookup request returns multiple results.
"""
asins = ['B0051QVESA', 'B005DOK8NW', 'B005890G8Y',
'B0051VVOB2', 'B005890G8O']
products = self.amazon.lookup(ItemId=','.join(asins))
assert_equals(len(products), 5)
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
def test_search(self):
"""Test Product Search.
Tests that a product search is working (by testing that results are
returned). And that each result has a title attribute. The test
fails if no results where returned.
"""
products = self.amazon.search(Keywords='kindle', SearchIndex='All')
for product in products:
assert_true(hasattr(product, 'title'))
break
else:
assert_true(False, 'No search results returned.')
def test_search_n(self):
"""Test Product Search N.
Tests that a product search n is working by testing that N results are
returned.
"""
products = self.amazon.search_n(
1,
Keywords='kindle',
SearchIndex='All'
)
assert_equals(len(products), 1)
def test_amazon_api_defaults_to_US(self):
"""Test Amazon API defaults to the US store."""
amazon = AmazonAPI(
AMAZON_ACCESS_KEY,
AMAZON_SECRET_KEY,
AMAZON_ASSOC_TAG
)
assert_equals(amazon.api.Region, "US")
def test_search_amazon_uk(self):
"""Test Poduct Search on Amazon UK.
Tests that a product search on Amazon UK is working and that the
currency of any of the returned products is GBP. The test fails if no
results were returned.
"""
amazon = AmazonAPI(
AMAZON_ACCESS_KEY,
AMAZON_SECRET_KEY,
AMAZON_ASSOC_TAG,
region="UK"
)
assert_equals(amazon.api.Region, "UK", "Region has not been set to UK")
products = amazon.search(Keywords='Kindle', SearchIndex='All')
currencies = [product.price_and_currency[1] for product in products]
assert_true(len(currencies), "No products found")
is_gbp = 'GBP' in currencies
assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though")
def test_similarity_lookup(self):
"""Test Similarity Lookup.
Tests that a similarity lookup for a kindle returns 10 results.
"""
products = self.amazon.similarity_lookup(ItemId="B0051QVF7A")
assert_equals(len(products), 10)
def test_product_attributes(self):
"""Test Product Attributes.
Tests that all product that are supposed to be accessible are.
"""
product = self.amazon.lookup(ItemId="B0051QVF7A")
for attribute in PRODUCT_ATTRIBUTES:
getattr(product, attribute)
def test_browse_node_lookup(self):
"""Test Browse Node Lookup.
Test that a lookup by Brose Node ID returns appropriate node.
"""
bnid = 2642129011
bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0]
assert_equals(bn.id, bnid)
assert_equals(bn.name, 'eBook Readers')
assert_equals(bn.is_category_root, False)
示例6: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
#.........这里部分代码省略.........
Tests that a product lookup for a kindle returns results and that the
main methods are working.
"""
product = self.amazon.lookup(ItemId="B0051QVF7A")
assert_equals(product.title, 'Kindle, Wi-Fi, 6" E Ink Display - for international shipment')
assert_equals(product.ean, "0814916014354")
assert_equals(product.large_image_url, "http://ecx.images-amazon.com/images/I/411H%2B731ZzL.jpg")
assert_equals(product.get_attribute("Publisher"), "Amazon Digital Services, Inc")
assert_equals(
product.get_attributes(["ItemDimensions.Width", "ItemDimensions.Height"]),
{"ItemDimensions.Width": "450", "ItemDimensions.Height": "34"},
)
assert_true(len(product.browse_nodes) > 0)
assert_equals(product.browse_nodes[0].id, 2642129011)
assert_equals(product.browse_nodes[0].name, "eBook Readers")
def test_batch_lookup(self):
"""Test Batch Product Lookup.
Tests that a batch product lookup request returns multiple results.
"""
asins = ["B0051QVESA", "B005DOK8NW", "B005890G8Y", "B0051VVOB2", "B005890G8O"]
products = self.amazon.lookup(ItemId=",".join(asins))
assert_equals(len(products), 5)
for i, product in enumerate(products):
assert_equals(asins[i], product.asin)
def test_search(self):
"""Test Product Search.
Tests that a product search is working (by testing that results are
returned). And that each result has a title attribute. The test
fails if no results where returned.
"""
products = self.amazon.search(Keywords="kindle", SearchIndex="All")
for product in products:
assert_true(hasattr(product, "title"))
break
else:
assert_true(False, "No search results returned.")
def test_search_n(self):
"""Test Product Search N.
Tests that a product search n is working by testing that N results are
returned.
"""
products = self.amazon.search_n(1, Keywords="kindle", SearchIndex="All")
assert_equals(len(products), 1)
def test_amazon_api_defaults_to_US(self):
"""Test Amazon API defaults to the US store."""
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
assert_equals(amazon.api.Region, "US")
def test_search_amazon_uk(self):
"""Test Poduct Search on Amazon UK.
Tests that a product search on Amazon UK is working and that the
currency of any of the returned products is GBP. The test fails if no
results were returned.
"""
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region="UK")
assert_equals(amazon.api.Region, "UK", "Region has not been set to UK")
products = amazon.search(Keywords="Kindle", SearchIndex="All")
currencies = [product.price_and_currency[1] for product in products]
assert_true(len(currencies), "No products found")
is_gbp = "GBP" in currencies
assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though")
def test_similarity_lookup(self):
"""Test Similarity Lookup.
Tests that a similarity lookup for a kindle returns 10 results.
"""
products = self.amazon.similarity_lookup(ItemId="B0051QVF7A")
assert_equals(len(products), 10)
def test_product_attributes(self):
"""Test Product Attributes.
Tests that all product that are supposed to be accessible are.
"""
product = self.amazon.lookup(ItemId="B0051QVF7A")
for attribute in PRODUCT_ATTRIBUTES:
getattr(product, attribute)
def test_browse_node_lookup(self):
"""Test Browse Node Lookup.
Test that a lookup by Brose Node ID returns appropriate node.
"""
bnid = 2642129011
bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0]
assert_equals(bn.id, bnid)
assert_equals(bn.name, "eBook Readers")
assert_equals(bn.is_category_root, False)
示例7: TestAmazonApi
# 需要导入模块: from amazon.api import AmazonAPI [as 别名]
# 或者: from amazon.api.AmazonAPI import browse_node_lookup [as 别名]
#.........这里部分代码省略.........
_AMAZON_SECRET_KEY,
_AMAZON_ASSOC_TAG,
region="UK"
)
assert_equals(amazon.api.Region, "UK", "Region has not been set to UK")
products = amazon.search(Keywords='Kindle', SearchIndex='All')
currencies = [product.price_and_currency[1] for product in products]
assert_true(len(currencies), "No products found")
is_gbp = 'GBP' in currencies
assert_true(is_gbp, "Currency is not GBP, cannot be Amazon UK, though")
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_similarity_lookup(self):
"""Test Similarity Lookup.
Tests that a similarity lookup for a kindle returns 10 results.
"""
products = self.amazon.similarity_lookup(ItemId=TEST_ASIN)
assert_true(len(products) > 5)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_product_attributes(self):
"""Test Product Attributes.
Tests that all product that are supposed to be accessible are.
"""
product = self.amazon.lookup(ItemId=TEST_ASIN)
for attribute in PRODUCT_ATTRIBUTES:
getattr(product, attribute)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_browse_node_lookup(self):
"""Test Browse Node Lookup.
Test that a lookup by Brose Node ID returns appropriate node.
"""
bnid = 2642129011
bn = self.amazon.browse_node_lookup(BrowseNodeId=bnid)[0]
assert_equals(bn.id, bnid)
assert_equals(bn.name, 'eBook Readers')
assert_equals(bn.is_category_root, False)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_obscure_date(self):
"""Test Obscure Date Formats
Test a product with an obscure date format
"""
product = self.amazon.lookup(ItemId="0933635869")
assert_equals(product.publication_date.year, 1992)
assert_equals(product.publication_date.month, 5)
assert_true(isinstance(product.publication_date, datetime.date))
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_single_creator(self):
"""Test a product with a single creator
"""
product = self.amazon.lookup(ItemId="B00005NZJA")
creators = dict(product.creators)
assert_equals(creators[u"Jonathan Davis"], u"Narrator")
assert_equals(len(creators.values()), 2)
@flaky(max_runs=3, rerun_filter=delay_rerun)
def test_multiple_creators(self):