本文整理汇总了Python中models.Product.price方法的典型用法代码示例。如果您正苦于以下问题:Python Product.price方法的具体用法?Python Product.price怎么用?Python Product.price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.price方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_category
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import price [as 别名]
def fetch_category(search_index, amazon_node_id):
api = caching.ResponseCachingAPI(
settings.AMAZON_AWS_KEY,
settings.AMAZON_SECRET_KEY,
settings.AMAZON_API_LOCALE,
settings.AMAZON_ASSOCIATE_TAG,
cachedir='cache',
cachetime=86400)
try:
for root in api.item_search(search_index, BrowseNode=str(amazon_node_id),
ResponseGroup=settings.AMAZON_RESPONSE_GROUP):
for item in root.Items.Item:
product = Product()
product.category = Category.objects.get(amazon_node_id=amazon_node_id)
product.asin = item.ASIN
product.title = unicode(item.ItemAttributes.Title)
product.detailpageurl = unicode(item.DetailPageURL)
product.manufacturer = unicode(getattr(item.ItemAttributes, 'Manufacturer', None))
product.publisher = unicode(getattr(item.ItemAttributes, 'Publisher', None))
product.brand = unicode(getattr(item.ItemAttributes, 'Brand', None))
product.popularity = getattr(item, 'SalesRank', 1000)
if hasattr(item, 'MediumImage'):
product.medium_image = getattr(item.MediumImage, 'URL', None)
if hasattr(item, 'LargeImage'):
product.large_image = getattr(item.LargeImage, 'URL', None)
if hasattr(item, 'EditorialReviews'):
product.description = unicode(getattr(item.EditorialReviews.EditorialReview, 'Content', None))
if hasattr(item.Offers, 'Offer'):
product.price = item.Offers.Offer.OfferListing.Price.FormattedPrice.pyval
elif hasattr(item.ItemAttributes, 'ListPrice'):
product.price = item.ItemAttributes.ListPrice.FormattedPrice.pyval
elif hasattr(item.OfferSummary, 'LowestUsedPrice'):
product.price = u'used from %s' % item.OfferSummary.LowestUsedPrice.FormattedPrice.pyval
else:
product.price = None
product.save()
except AWSError, e:
if e.code == 'AWS.ParameterOutOfRange':
pass # reached the api limit of 10 pages
else:
raise ValidationError(message=e.msg)
示例2: SaveChanges
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import price [as 别名]
def SaveChanges(self):
for row in self.change_rows.keys():
row = int(row)
product = Product()
product.category = models.ALL_PRODUCT_TYPE[self.m_grid5.GetCellValue(row, 0)]
product.type = self.m_grid5.GetCellValue(row, 1)
product.length = self.m_grid5.GetCellValue(row, 2)
product.width = self.m_grid5.GetCellValue(row, 3)
product.height = self.m_grid5.GetCellValue(row, 4)
product.per_weight = self.m_grid5.GetCellValue(row, 5)
product.price = self.m_grid5.GetCellValue(row, 6)
db.UpdateProduct(product)
for new_row in self.new_products.keys():
product = Product()
product.category = models.ALL_PRODUCT_TYPE[self.m_grid5.GetCellValue(row, 0)]
product.type = self.m_grid5.GetCellValue(new_row, 1)
product.length = self.m_grid5.GetCellValue(new_row, 2)
product.width = self.m_grid5.GetCellValue(new_row, 3)
product.height = self.m_grid5.GetCellValue(new_row, 4)
product.per_weight = self.m_grid5.GetCellValue(new_row, 5)
product.price = self.m_grid5.GetCellValue(new_row, 6)
db.InsertProduct(product)
示例3: GetAllProducts
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import price [as 别名]
def GetAllProducts():
"""获取所有的产品数据"""
db_cur = db_conn.cursor()
db_cur.execute(SQL_ALL_PRODUCT)
all_products = {}
for category in models.ALL_PRODUCT_TYPE.values():
all_products[category] = {}
for row in db_cur:
rec = Product()
rec.category = str(row[0])
rec.type = row[1]
rec.length = str(row[2])
rec.width = str(row[3])
rec.height = str(row[4])
rec.per_weight = str(row[5])
rec.price = str(row[6])
all_products[rec.category][rec.type] = rec
return all_products
示例4: crawl_listing
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import price [as 别名]
def crawl_listing(self, url, ctx='', **kwargs):
res = requests.get(url)
res.raise_for_status()
tree = lxml.html.fromstring(res.content)
category = Category.objects(key=kwargs.get('key')).first()
if not category:
common_failed.send(sender=ctx, url=url, reason='category %s not found in db' % kwargs.get('key'))
return
product_nodes = tree.cssselect('div#searchResults a')
for product_node in product_nodes:
price = None; listprice = None
price = product_node.cssselect('.price-6pm')[0].text
listprice_node = product_node.cssselect('.discount')
listprice = ''.join(listprice_node[0].xpath('text()')) if listprice_node else None
# eliminate products of no discountIndexError:
if price is None or listprice is None:
# common_failed.send(sender=ctx, url=url, \
# reason='listing product %s.%s cannot crawl price info -> %s / %s' % (key, title, price, listprice))
continue
key = product_node.get('data-product-id')
if not key:
common_failed.send(sender=ctx, url=url, reason='listing product has no key')
continue
combine_url = product_node.get('href')
key = '%s_%s' % (key, combine_url.split('/')[-1])
match = re.search(r'https?://.+', combine_url)
if not match:
combine_url = '%s%s' % (HOST, combine_url)
brand = product_node.cssselect('.brandName')[0].text.strip()
title = product_node.cssselect('.productName')[0].text.strip()
is_new = False; is_updated = False
product = Product.objects(key=key).first()
if not product:
is_new = True
product = Product(key=key)
product.updated = False
product.event_type = False
if title and title != product.title:
product.title = title
is_updated = True
if brand and brand != product.brand:
product.brand = brand
is_updated = True
if combine_url and combine_url != product.combine_url:
product.combine_url = combine_url
is_updated = True
if price and price != product.price:
product.price = price
is_updated = True
if listprice and listprice != product.listprice:
product.listprice = listprice
is_updated = True
if category.cats and set(category.cats).difference(product.dept):
product.dept = list(set(category.cats) | set(product.dept or []))
is_updated = True
if category.key not in product.category_key:
product.category_key.append(category.key)
is_updated = True
if is_updated:
product.list_update_time = datetime.utcnow()
# To pick the product which fit our needs, such as a certain discount, brand, dept etc.
selected = Picker(site='6pm').pick(product)
if not selected:
continue
product.hit_time = datetime.utcnow()
product.save()
common_saved.send(sender=ctx, obj_type='Product', key=product.key, url=product.combine_url, \
is_new=is_new, is_updated=((not is_new) and is_updated) )
print product.key; print product.brand; print product.title; \
print product.price, ' / ', product.listprice; print product.combine_url; \
print product.dept; print
# Go to the next page to keep on crawling.
next_page = None
page_node = tree.cssselect('div.pagination')
if not page_node:
return
last_node =page_node[0].cssselect('.last')
if last_node:
#.........这里部分代码省略.........
示例5: _parse_product
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import price [as 别名]
def _parse_product(self, event_id, asins, cAsins, prefix_url, product_data, ctx):
""" no video info, list_info, summary
:param event_id: this product belongs to the event's id
:param asins: all asins info in this event
:param cAsins: all casins info in this event
:param prefix_url: image and js prefix_url, probably 'http://z-ecx.images-amazon.com/images/I/'
:param product_data: product data in this product
"""
asin = product_data['asin']
casin = product_data['cAsin']
title = product_data['title'].encode('utf-8') # color is in title
# image_urls = [product_data['image']] + product_data['altImages'] # one picture, altImages is []
if 'listPrice' in product_data:
listprice = product_data['listPrice']['display'] # or 'amount', if isRange: True, don't know what 'amount' will be
else: listprice = ''
price = product_data['ourPrice']['display']
sizes = []
if product_data['teenagers']: # no size it is {}
for k, v in product_data['teenagers'].iteritems():
if v['size'] not in sizes: sizes.append(v['size'])
# tag is not precision. e.g. a bag is in shoes
# tag = product_data['productGL'] if 'productGL' in product_data else '' # 'apparel', 'home', 'jewelry', ''
soldout_link = 'http://www.myhabit.com/request/getBuyableAsinInfo?asin={0}&saleId={1}&flavor=parent&sid=177-4704555-7345351'.format(asin, event_id)
# one soldout link contains this asin's all color.
ret = req.get(soldout_link)
jsdata = json.loads(ret.content)
key_list = sorted(jsdata['buyableAsin'].keys())
len_sizes = len(sizes)
soldout = False
if len_sizes == 0:
if jsdata['buyableAsin'][casin]['stats']['remaining']['claimed'] == 0:
soldout = True
else:
soldout = False
else: # more than one size.
if 'asin' in key_list: key_list.remove('asin')
if 'privateSaleID' in key_list: key_list.remove('privateSaleID')
count = 0
for l in key_list:
if l == casin or (count > 0 and count < len_sizes):
count += 1
if jsdata['buyableAsin'][l]['stats']['remaining']['claimed'] == 0:
soldout = True
else:
soldout = False
break
# if casin in cAsins and 'soldOut' in cAsins[casin] and cAsins[casin]['soldOut'] == 1:
# soldout = True
# else: soldout = False
jslink = prefix_url + asins[asin]['url'] if asin in asins else ''
combine_url = 'http://www.myhabit.com/homepage#page=d&sale={0}&asin={1}&cAsin={2}'.format(event_id, asin, casin)
is_new, is_updated = False, False
product = Product.objects(key=casin).first()
if not product:
is_new = True
product = Product(key=casin)
product.combine_url = combine_url
product.asin = asin
product.title = title
# product.image_urls = image_urls
product.listprice = listprice
product.price = price
product.sizes = sizes
product.soldout = soldout
product.updated = False
else:
if soldout and product.soldout != soldout:
product.soldout = True
is_updated = True
product.update_history.update({ 'soldout': datetime.utcnow() })
if product.title != title:
product.title = title
product.update_history.update({ 'title': datetime.utcnow() })
if product.combine_url != combine_url:
product.combine_url = combine_url
product.update_history.update({ 'combine_url': datetime.utcnow() })
if product.listprice != listprice:
product.listprice = listprice
product.update_history.update({ 'listprice': datetime.utcnow() })
if product.price != price:
product.price = price
product.update_history.update({ 'price': datetime.utcnow() })
if event_id not in product.event_id: product.event_id.append(event_id)
product.jslink = jslink
product.list_update_time = datetime.utcnow()
product.save()
common_saved.send(sender=ctx, obj_type='Product', key=casin, url=product.combine_url, is_new=is_new, is_updated=is_updated)
return casin