def get_or_create_rate_chart(self, listing_id): try: rate_chart_map = ListingRateChartMap.objects.get( listing_id=listing_id) if rate_chart_map.rate_chart: return rate_chart_map.rate_chart except ListingRateChartMap.DoesNotExist: pass results = listing_solr_search('id:%s' % listing_id) if results and results.results and len(results.results) > 0: listing = results.results[0] product = Product() product.title = listing.get('title', '') product.description = listing.get('description', '') product.currency = listing.get('currency', 'inr') product.brand = self.get_other_brand('Other') product.model = '' product.category = self.get_other_category('Other') product.type = 'normal' product.status = 'unavailable' product.save() rate_chart = SellerRateChart() rate_chart.listing_id = listing_id rate_chart.product = product rate_chart.seller = self.get_seller(listing.get('userId', 0)) rate_chart.status = 'unavailable' rate_chart.sku = listing.get('sku', '') rate_chart.condition = 'new' rate_chart.is_prefered = True rate_chart.list_price = Decimal(str(listing.get('mrp', 0))) rate_chart.offer_price = Decimal(str(listing.get('askingPrice', 0))) if rate_chart.offer_price > rate_chart.list_price: rate_chart.list_price = rate_chart.offer_price rate_chart.warranty = listing.get('warranty', '') rate_chart.gift_title = listing.get('gifts', '') rate_chart.shipping_charges = Decimal( str(listing.get('shippingCharges', '0.0'))) rate_chart.shipping_duration = listing.get('shippingDuration', '7-10 working days') rate_chart.availability = self.get_available_every_where() rate_chart.stock_status = 'notavailable' rate_chart.status = 'deleted' rate_chart.save() listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id, rate_chart=rate_chart) listing_rate_chart_map.save() return rate_chart return None
def get_or_create_rate_chart(self, listing_id): try: rate_chart_map = ListingRateChartMap.objects.get( listing_id = listing_id) if rate_chart_map.rate_chart: return rate_chart_map.rate_chart except ListingRateChartMap.DoesNotExist: pass results = listing_solr_search('id:%s' % listing_id) if results and results.results and len(results.results) > 0: listing = results.results[0] product = Product() product.title = listing.get('title','') product.description = listing.get('description','') product.currency = listing.get('currency','inr') product.brand = self.get_other_brand('Other') product.model = '' product.category = self.get_other_category('Other') product.type = 'normal' product.status = 'unavailable' product.save() rate_chart = SellerRateChart() rate_chart.listing_id = listing_id rate_chart.product = product rate_chart.seller = self.get_seller(listing.get('userId',0)) rate_chart.status = 'unavailable' rate_chart.sku = listing.get('sku', '') rate_chart.condition = 'new' rate_chart.is_prefered = True rate_chart.list_price = Decimal(str(listing.get('mrp',0))) rate_chart.offer_price = Decimal(str(listing.get('askingPrice',0))) if rate_chart.offer_price > rate_chart.list_price: rate_chart.list_price = rate_chart.offer_price rate_chart.warranty = listing.get('warranty','') rate_chart.gift_title = listing.get('gifts','') rate_chart.shipping_charges = Decimal(str(listing.get('shippingCharges','0.0'))) rate_chart.shipping_duration = listing.get('shippingDuration','7-10 working days') rate_chart.availability = self.get_available_every_where() rate_chart.stock_status = 'notavailable' rate_chart.status = 'deleted' rate_chart.save() listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id, rate_chart=rate_chart) listing_rate_chart_map.save() return rate_chart return None
def create_product_map(self): file = open("/tmp/uniq-product-ids.txt","r") ids = [] id_map = {} for line in file: id = line.strip() ids.append(id) file.close() wb = pyExcelerator.Workbook() ws = wb.add_sheet('data') ws.write(0,0,) row = 0 col = 0 item_info = ['old_id','old_title','options','ids','status'] for x in item_info: ws.write(row,col,x) col += 1 for id in ids: try: ListingRateChartMap.objects.get(listing_id = id) continue except ListingRateChartMap.DoesNotExist: pass row += 1 try: results = listing_solr_search('id:%s' % id) if results and results.results and len(results.results) > 0: prod = results.results[0] else: log.error('Have not found a matching product from solr %s' % id) continue if prod['isActive']: if 'sku' in prod: try: src = SellerRateChart.objects.get(sku=prod['sku'], seller=self.get_seller(prod['userId'])) listing_rate_chart_map = ListingRateChartMap(listing_id=id, rate_chart=src) listing_rate_chart_map.save() continue except SellerRateChart.DoesNotExist: product = Product.objects.filter(title__contains=prod['title']) ws.write(row,0,id) ws.write(row,1,prod['title']) ws.write(row,2,"\r\n ".join(x.title for x in product)) ws.write(row,3,", ".join(str(x.id) for x in product)) ws.write(row,4,"active") else: product = Product.objects.filter(title__contains=prod['title']) ws.write(row,0,id) ws.write(row,1,prod['title']) ws.write(row,2,"\r\n ".join(x.title for x in product)) ws.write(row,3,", ".join(str(x.id) for x in product)) ws.write(row,4,"active") else: if 'sku' in prod: if prod['sku']: try: src = SellerRateChart.objects.get(sku=prod['sku'], seller=self.get_seller(prod['userId'])) listing_rate_chart_map = ListingRateChartMap(listing_id=id, rate_chart=src) listing_rate_chart_map.save() continue except SellerRateChart.DoesNotExist: product = Product.objects.filter(title__contains=prod['title']) ws.write(row,0,id) ws.write(row,1,prod['title']) ws.write(row,2,"\r\n ".join(x.title for x in product)) ws.write(row,3,", ".join(str(x.id) for x in product)) ws.write(row,4,"inactive") else: product = Product.objects.filter(title__contains=prod['title']) ws.write(row,0,id) ws.write(row,1,prod['title']) ws.write(row,2,"\r\n ".join(x.title for x in product)) ws.write(row,3,", ".join(str(x.id) for x in product)) ws.write(row,4,"inactive") except Exception,e: log.exception('Error creating product mapping %s' % repr(e))
def create_product_map(self): file = open("/tmp/uniq-product-ids.txt", "r") ids = [] id_map = {} for line in file: id = line.strip() ids.append(id) file.close() wb = pyExcelerator.Workbook() ws = wb.add_sheet('data') ws.write( 0, 0, ) row = 0 col = 0 item_info = ['old_id', 'old_title', 'options', 'ids', 'status'] for x in item_info: ws.write(row, col, x) col += 1 for id in ids: try: ListingRateChartMap.objects.get(listing_id=id) continue except ListingRateChartMap.DoesNotExist: pass row += 1 try: results = listing_solr_search('id:%s' % id) if results and results.results and len(results.results) > 0: prod = results.results[0] else: log.error( 'Have not found a matching product from solr %s' % id) continue if prod['isActive']: if 'sku' in prod: try: src = SellerRateChart.objects.get( sku=prod['sku'], seller=self.get_seller(prod['userId'])) listing_rate_chart_map = ListingRateChartMap( listing_id=id, rate_chart=src) listing_rate_chart_map.save() continue except SellerRateChart.DoesNotExist: product = Product.objects.filter( title__contains=prod['title']) ws.write(row, 0, id) ws.write(row, 1, prod['title']) ws.write(row, 2, "\r\n ".join(x.title for x in product)) ws.write(row, 3, ", ".join(str(x.id) for x in product)) ws.write(row, 4, "active") else: product = Product.objects.filter( title__contains=prod['title']) ws.write(row, 0, id) ws.write(row, 1, prod['title']) ws.write(row, 2, "\r\n ".join(x.title for x in product)) ws.write(row, 3, ", ".join(str(x.id) for x in product)) ws.write(row, 4, "active") else: if 'sku' in prod: if prod['sku']: try: src = SellerRateChart.objects.get( sku=prod['sku'], seller=self.get_seller(prod['userId'])) listing_rate_chart_map = ListingRateChartMap( listing_id=id, rate_chart=src) listing_rate_chart_map.save() continue except SellerRateChart.DoesNotExist: product = Product.objects.filter( title__contains=prod['title']) ws.write(row, 0, id) ws.write(row, 1, prod['title']) ws.write( row, 2, "\r\n ".join(x.title for x in product)) ws.write(row, 3, ", ".join(str(x.id) for x in product)) ws.write(row, 4, "inactive") else: product = Product.objects.filter( title__contains=prod['title']) ws.write(row, 0, id) ws.write(row, 1, prod['title']) ws.write(row, 2, "\r\n ".join(x.title for x in product)) ws.write(row, 3, ", ".join(str(x.id) for x in product)) ws.write(row, 4, "inactive") except Exception, e: log.exception('Error creating product mapping %s' % repr(e))