コード例 #1
0
ファイル: ann_family.py プロジェクト: khsr/django-shelf
    def _create_product_item(self, name, prod_id, prod_url, price, saleprice, gender, img_url, promo_text, prod_desc):
        from django.core.exceptions import ObjectDoesNotExist

        b = Brands.objects.get(name = self.store_name)

        existing_item = ProductModel.objects.filter(brand = b).filter(c_idx = prod_id)
        print existing_item
        if len(existing_item) > 0:
            print "Item " + str(existing_item[0]) + " EXISTS. Not creating new one. Returning...."
            return (existing_item[0], False)

        logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
        item = ProductModel(brand = b,
                            c_idx = prod_id,
                            name = name,
                            prod_url = prod_url,
                            price = price,
                            saleprice = saleprice,
                            promo_text = promo_text,
                            gender = gender,
                            img_url = img_url,
                            description = prod_desc,
                            insert_date = self.insert_date,)

        #print item
        item.save()
        print "CREATING NEW PRODUCT MODEL OBJ"
        #return (item.save(), True)
        return (item, True)
コード例 #2
0
ファイル: ss_links_jcrew.py プロジェクト: khsr/django-shelf
    def _create_product_item(self, name, prod_id, prod_url, price, saleprice, 
                             gender, img_url, prod_desc):
        b = Brands.objects.get(name = self.store_name)

        existing_item = ProductModel.objects.filter(brand = b).filter(idx = prod_id)
        print existing_item
        if len(existing_item) > 0:
            print "Item " + str(existing_item[0]) + " EXISTS. Not creating new one. Returning...."
            return (existing_item[0], False)
        
        item = ProductModel(brand = b, 
                            idx = prod_id,
                            name = name,
                            prod_url = prod_url,
                            price = price,
                            saleprice = saleprice,
                            promo_text = "None",
                            gender = gender,
                            img_url = img_url,
                            description = prod_desc,
                            insert_date = self.insert_date,)
        
         
        logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
        print "Prod id " + str(prod_id) + " url " + str(prod_url) + " img " + str(img_url)
        
        #print item
        
        return (item.save(), True)
コード例 #3
0
    def _create_product_item(self, name, prod_id, prod_url, price, saleprice,
                             gender, img_url, promo_text, prod_desc):
        from django.core.exceptions import ObjectDoesNotExist
        store_name = "-1"
        if 'bananarepublic' in prod_url:
            store_name = "Banana Republic"
        elif 'oldnavy' in prod_url:
            store_name = 'Old Navy'
        elif 'athleta' in prod_url:
            store_name = 'Athleta'
        elif 'piperlime' in prod_url:
            store_name = "Piperlime"
        elif 'www.gap.com' in prod_url:
            store_name = "Gap"
        else:
            return (None, False)

        b = Brands.objects.get(name=store_name)

        existing_item = ProductModel.objects.filter(brand=b).filter(
            c_idx=prod_id)
        print existing_item
        if len(existing_item) > 0:
            print "Item " + str(
                existing_item[0]
            ) + " EXISTS. Not creating new one. Returning...."
            #existing_item[0].insert_date = self.insert_date
            #existing_item[0].save()
            return (existing_item[0], False)

        logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
        item = ProductModel(
            brand=b,
            c_idx=prod_id,
            name=name,
            prod_url=prod_url,
            price=price,
            saleprice=saleprice,
            promo_text=promo_text,
            gender=gender,
            img_url=img_url,
            description=prod_desc,
            insert_date=self.insert_date,
        )

        #print item
        item.save()
        print "CREATING NEW PRODUCT MODEL OBJ"
        #return (item.save(), True)
        return (item, True)
コード例 #4
0
    def _create_product_item(self, name, prod_id, prod_url, price, saleprice,
                             gender, img_url, promo_text, prod_desc):
        from django.core.exceptions import ObjectDoesNotExist
        if 'www.bananarepublic.com' in prod_url:
            store = "Banana Republic"
        if 'www.gap.com' in prod_url:
            store = "Gap"
        if 'oldnavy' in prod_url:
            store = "Old Navy"
        if 'athleta' in prod_url:
            store = "Athleta"
        b = Brands.objects.get(name=store)

        try:
            existing_item = ProductModel.objects.filter(brand=b).get(
                idx=prod_id)
            result = existing_item
            if result.gender != gender:
                result.gender = gender
                result.save()
            logging.critical(
                "Item " + str(result) +
                " EXISTS. Not creating new one. Returning....gender " +
                result.gender)
            return (result, False)
        except ObjectDoesNotExist:

            print "Prod id " + str(prod_id) + " url " + str(prod_url) + " img " + str(img_url) + " gender " + gender \
                    + " price " + str(price)
            item = ProductModel(
                brand=b,
                idx=prod_id,
                name=name,
                prod_url=prod_url,
                price=price,
                saleprice=saleprice,
                promo_text=promo_text,
                gender=gender,
                img_url=img_url,
                description=prod_desc,
                insert_date=self.insert_date,
            )

            logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
            logging.critical("Prod id " + str(prod_id) + " url " +
                             str(prod_url) + " img " + str(img_url) +
                             " gender " + gender)

            #print item
            return (item.save(), True)
コード例 #5
0
    def _create_product_item(self, name, prod_id, prod_url, price, saleprice,
                             gender, img_url, promo_text, prod_desc):
        b = Brands.objects.get(name=self.store_name)

        existing_item = ProductModel.objects.filter(brand=b).filter(
            idx=prod_id)
        print existing_item
        if len(existing_item) > 0:
            print "Item " + str(
                existing_item[0]
            ) + " EXISTS. Not creating new one. Returning...."
            return (existing_item[0], False)

        item = ProductModel(
            brand=b,
            idx=prod_id,
            name=name,
            prod_url=prod_url,
            price=price,
            saleprice=saleprice,
            promo_text=promo_text,
            gender=gender,
            img_url=img_url,
            description=prod_desc,
            insert_date=self.insert_date,
        )

        logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
        print "Prod id " + str(prod_id) + " url " + str(
            prod_url) + " img " + str(img_url)
        '''item['brand'] = b
        item['idx'] = prod_id
        item['name'] = name
        item['prod_url'] = prod_url
        item['price'] = price
        item['saleprice'] = saleprice
        item['promo_text'] = promo_text
        item['err_text'] = "None"
        item['gender'] = gender
        item['img_url'] = img_url
        item['description'] = prod_desc
        item['insert_date'] = self.insert_date
        '''
        #print item
        print "CREATING NEW PRODUCT MODEL OBJ"
        return (item.save(), True)
コード例 #6
0
ファイル: nyco.py プロジェクト: khsr/django-shelf
    def _create_product_item(self, orig_url, name, prod_id, prod_url, price, saleprice, gender, img_url, promo_text, prod_desc):
        from django.core.exceptions import ObjectDoesNotExist

        b = Brands.objects.get(name = self.store_name)

        existing_item = ProductModel.objects.filter(brand = b, c_idx = prod_id)
        print existing_item
        if len(existing_item) > 0:
            print "Item " + str(existing_item[0]) + " EXISTS. Not creating new one. We got " + str(len(existing_item)) + " number of copies"

            #correct the c_idx
            for e in existing_item:
                if e.prod_url != orig_url:
                    print "Correcting url: cur_url: " + str(e.prod_url) + " prod_url: " + str(prod_url)
                    e.c_idx = prod_id
                    e.prod_url = prod_url
                    e.save()
            #existing_item[0].insert_date = self.insert_date
            #existing_item[0].save()
            return (existing_item[0], False)

        logging.critical("CREATE_PRODUCT OBJ: foreign key " + str(b))
        item = ProductModel(brand = b,
                            c_idx = prod_id,
                            name = name,
                            prod_url = prod_url,
                            price = price,
                            saleprice = saleprice,
                            promo_text = promo_text,
                            gender = gender,
                            img_url = img_url,
                            description = prod_desc,
                            insert_date = self.insert_date,)

        #print item
        item.save()
        print "CREATING NEW PRODUCT MODEL OBJ"
        #return (item.save(), True)
        return (item, True)