本文整理汇总了Python中amazonproduct.api.API.similarity_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python API.similarity_lookup方法的具体用法?Python API.similarity_lookup怎么用?Python API.similarity_lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazonproduct.api.API
的用法示例。
在下文中一共展示了API.similarity_lookup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: amazon
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import similarity_lookup [as 别名]
def amazon(query):
api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
similar_root = api.similarity_lookup('B0058U6DQC', ResponseGroup='Large')
product_root = api.item_lookup('B0058U6DQC', ResponseGroup='Large')
product_root = api.item_search(title='unicorn', ResponseGroup='Large')
more_products = api.item_search('Books', Publisher='Galileo Press')
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
nspace = similar_root.nsmap.get(None, '')
similar_products = similar_root.xpath('//aws:Items/aws:Item',
namespaces={'aws' : nspace})
# more_products = product_root.xpath('//aws:Items/aws:Item',
# namespaces={'aws' : nspace})
return render_template("amazon.html", similar_products=similar_products, more_products = more_products, query=query)
示例2: search
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import similarity_lookup [as 别名]
def search():
form = SearchForm()
if form.validate_on_submit():
referrer = form.referrer.data
query = form.query.data
results = model.session.query(model.Library).filter(model.Library.product_desc.like('%'+ query + '%')).all()
if not results:
#redirect to new page with amazon search results
return redirect(url_for('amazon_bottlenose2', query=query, referrer=referrer))
else:
for i in results:
similar_products = None
if i.product.asin:
asin = i.product.asin
api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
try:
similar_root = api.similarity_lookup(asin, ResponseGroup='Large')
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
nspace = similar_root.nsmap.get(None, '')
similar_products = similar_root.xpath('//aws:Items/aws:Item',
namespaces={'aws' : nspace})
except:
similar_products = None
#render page with search results
if referrer == 'dashboard':
return render_template('results.html', results=results, similar_products=similar_products)
else:
form = AddProductForm()
return render_template('add_product_results.html', results=results, similar_products=similar_products, form=form)
# else:
# flash("Invalid Search")
return render_template("search.html", form=form)
示例3: API
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import similarity_lookup [as 别名]
"""
Find similar items to "Small Favor: A Novel of the Dresden Files"
(ASIN 0451462009).
"""
from amazonproduct.api import API
from config import AWS_KEY, SECRET_KEY
if __name__ == '__main__':
api = API(AWS_KEY, SECRET_KEY, 'us')
root = api.similarity_lookup('0451462009')
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
nspace = root.nsmap.get(None, '')
books = root.xpath('//aws:Items/aws:Item',
namespaces={'aws' : nspace})
for book in books:
print 'ASIN %-10s' % book.ASIN,
print unicode(book.ItemAttributes.Author), ':',
print unicode(book.ItemAttributes.Title)