本文整理匯總了Python中products.models.Product.wikipedia方法的典型用法代碼示例。如果您正苦於以下問題:Python Product.wikipedia方法的具體用法?Python Product.wikipedia怎麽用?Python Product.wikipedia使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類products.models.Product
的用法示例。
在下文中一共展示了Product.wikipedia方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: urlopen
# 需要導入模塊: from products.models import Product [as 別名]
# 或者: from products.models.Product import wikipedia [as 別名]
for beer in beers:
print "Beer: %s" % beer
page_url = None
results = None
try:
fd = urlopen(wikipedia_search % beer.replace(' ', '+'))
_, results = json.loads(fd.read())
if not len(results):
raise Exception('No results')
except Exception, e:
print 'Woops: %s' % (str(e),)
# Select page
if results:
page = results[0]
filtered = [r for r in results if u'bi\xe8re' in r]
page = len(filtered) == 1 and filtered[0] or results[0]
page_url = wikipedia_article % page.replace(' ', '_')
# Add beer
try:
b = Product(name=beer, category=category, creator=owner)
if page_url is not None:
b.wikipedia = page_url
b.save()
print 'Created beer #%d %s ' % (b.id, b.slug)
except Exception, e:
print 'Already exist : %s' % (str(e),)
print 20*'-'