Пример #1
0
    def handle(self, *args, **options):
        seller_id = options['seller_id']
        store = Store(seller_id=seller_id)
        products = ProductForStore.objects.filter(store_id=seller_id).exclude(
            sku=None)
        ids = products.values_list('sku', flat=True)
        params = [{
            'ids': _ids,
            'attributes': 'status,id'
        } for _ids in store.split_ids(ids)]
        path = 'items'

        results = store.map_pool_get([path] * len(params), params)
        posts = defaultdict(list)
        for product in [_ for _ in results if _]:
            if product['code'] == 200:
                if product['body']['status'] == 'closed':
                    posts['deleted'].append(product['body']['id'])
                elif product['body']['status'] == 'active':
                    posts['active'].append(product['body']['id'])
                elif product['body']['status'] == 'paused':
                    posts['paused'].append(product['body']['id'])
                elif product['body']['status'] == 'under_review':
                    posts['under_review'].append(product['body']['id'])
                elif product['body']['status'] == 'inactive':
                    posts['inactive'].append(product['body']['id'])
            else:
                logging.getLogger('log_three').info(product)

        logging.getLogger('log_three').info(
            f"{len(posts['deleted'])} Productos eliminados recientemente.")
        ProductForStore.objects.filter(sku__in=posts['deleted']).update(
            status=ProductForStore.CLOSED)

        logging.getLogger('log_three').info(
            f"{len(posts['active'])} Productos activos.")
        ProductForStore.objects.filter(sku__in=posts['active']).update(
            status=ProductForStore.ACTIVE)

        logging.getLogger('log_three').info(
            f"{len(posts['paused'])} Productos pausados.")
        ProductForStore.objects.filter(sku__in=posts['paused']).update(
            status=ProductForStore.PAUSED)

        logging.getLogger('log_three').info(
            f"{len(posts['under_review'])} Productos bajo revision de ML.")
        ProductForStore.objects.filter(sku__in=posts['under_review']).update(
            status=ProductForStore.UNDER_REVIEW)

        logging.getLogger('log_three').info(
            f"{len(posts['inactive'])} Productos inactivos por revision de ML."
        )
        ProductForStore.objects.filter(sku__in=posts['inactive']).update(
            status=ProductForStore.UNDER_REVIEW)
Пример #2
0
    def handle(self, *args, **options):
        seller_id=config('MELI_ME_ID')
        store = Store(seller_id=seller_id)

        path = '/questions/search'
        params = {
            'seller_id':seller_id,
            'status':'UNANSWERED',
            'offset':0,
        }
        questions_api = store.get(path, params)

        total = questions_api['total']
        limit = questions_api['limit']

        questions_draw = questions_api['questions']

        params = [{
            'seller_id':seller_id,
            'status':'UNANSWERED',
            'offset':offset,
            'attributes':'questions'
        }for offset in range(limit,total,limit)]

        for questions_api in store.map_pool_get([path]*len(params), params):
            questions_draw += questions_api['questions']

        questions_draw = questions_draw[::-1]

        count=0
        for question_draw in questions_draw:
            question,exist =  new_question(question_draw)
            if exist:
                break
            else:
                logging.getLogger('log_three').info(f'Nueva Pregunta de {question.buyer} en \
{question.product.title} a las {question.date_created.strftime("%H:%M:%S")}')        
                count +=1

        logging.getLogger('log_three').info(f'Nuevas Preguntas: {count}. Sin responder: {total}')